From db5d9b57f832e242abb61df9670168df12d9283e Mon Sep 17 00:00:00 2001 From: miruka Date: Mon, 27 Jul 2020 04:32:00 -0400 Subject: [PATCH] RoomDelegate subtitle: lazy-fetch missing profiles --- src/gui/MainPane/RoomDelegate.qml | 32 ++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/gui/MainPane/RoomDelegate.qml b/src/gui/MainPane/RoomDelegate.qml index 9ba45fcc..ca7f03b2 100644 --- a/src/gui/MainPane/RoomDelegate.qml +++ b/src/gui/MainPane/RoomDelegate.qml @@ -11,6 +11,7 @@ import "../PythonBridge" HTile { id: room + property Future fetchProfilesFuture: null property Future loadEventsFuture: null property bool moreToLoad: true @@ -200,17 +201,20 @@ HTile { } } - Component.onDestruction: if (loadEventsFuture) loadEventsFuture.cancel() + Component.onDestruction: { + if (fetchProfilesFuture) fetchProfilesFuture.cancel() + if (loadEventsFuture) loadEventsFuture.cancel() + } Timer { + interval: 1000 + triggeredOnStart: true running: ! accountModel.connecting && accountModel.presence !== "offline" && ! lastEvent && moreToLoad - interval: 1000 - triggeredOnStart: true onTriggered: if (! loadEventsFuture) { loadEventsFuture = py.callClientCoro( model.for_account, @@ -224,4 +228,26 @@ HTile { ) } } + + Timer { + // Ensure this event stays long enough for bothering to + // fetch the profile to be worth it + interval: 500 + running: + ! accountModel.connecting && + accountModel.presence !== "offline" && + lastEvent && + lastEvent.fetch_profile + + onTriggered: { + if (fetchProfilesFuture) fetchProfilesFuture.cancel() + + fetchProfilesFuture = py.callClientCoro( + model.for_account, + "get_event_profiles", + [model.id, lastEvent.id], + () => { if (room) fetchProfilesFuture = null }, + ) + } + } }