From deee7e3552b40fce1e5b167edef8947006af077f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Mon, 28 Aug 2023 14:42:07 +0200 Subject: [PATCH] room-history: Remove supposed guard against loading The purpose seems to be to guard when calling load because the timeline is ready, but the items are not yet loaded in the history. However that also prevents to load more items when the view is not full. It is more of a bug to not be able to load events when the view is not full, than to make one extra request. --- src/session/view/content/room_history/mod.rs | 31 ++++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/session/view/content/room_history/mod.rs b/src/session/view/content/room_history/mod.rs index 4466bd2a..56b527cd 100644 --- a/src/session/view/content/room_history/mod.rs +++ b/src/session/view/content/room_history/mod.rs @@ -1044,17 +1044,22 @@ impl RoomHistory { let Some(room) = self.room() else { return false; }; - let timeline_items = room.timeline().items(); - let adj = self.imp().listview.vadjustment().unwrap(); + let timeline = room.timeline(); - if adj.value() <= 0.0 && timeline_items.n_items() > 0 { - // The room history is loading the timeline items, so wait until they are done. + if !timeline.can_load() { + // We will retry when timeline is ready. return false; } - // Load more messages when the user gets close to the end of the known room + if timeline.is_empty() { + // We definitely want messages if the timeline is ready but empty. + return true; + }; + + // Load more messages when the user gets close to the top of the known room // history. Use the page size twice to detect if the user gets close to - // the end. + // the top. + let adj = self.imp().listview.vadjustment().unwrap(); adj.value() < adj.page_size() * 2.0 || adj.upper() <= adj.page_size() / 2.0 } @@ -1065,19 +1070,13 @@ impl RoomHistory { return; } + if !self.need_messages() { + return; + } + let Some(room) = self.room() else { return; }; - let timeline = room.timeline(); - - if !timeline.can_load() { - // We will retry when the timeline is ready. - return; - } - - if !self.need_messages() && !room.timeline().is_empty() { - return; - } imp.is_loading.set(true);