From a11884ef2c1ed30d4aef08cc9773f1d0d341f70d Mon Sep 17 00:00:00 2001 From: alanpoon Date: Fri, 11 Oct 2024 15:03:50 +0800 Subject: [PATCH 1/2] added send_pagination_request_based_on_scroll_pos --- src/home/room_screen.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 904f86c9..74cc8a51 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -1269,6 +1269,7 @@ impl Widget for RoomScreen { } // Handle sending any read receipts for the current logged-in user. + self.send_pagination_request_based_on_scroll_pos(cx, actions); self.send_user_read_receipts_based_on_scroll_pos(cx, actions); // Handle the cancel reply button being clicked. @@ -1529,6 +1530,7 @@ impl RoomScreen { /// Redraws this RoomScreen view if any updates were applied. fn process_timeline_updates(&mut self, cx: &mut Cx) { let portal_list = self.portal_list(id!(list)); + let top_space = self.view(id!(top_space)); let curr_first_id = portal_list.first_id(); let Some(tl) = self.tl_state.as_mut() else { return }; @@ -1613,14 +1615,14 @@ impl RoomScreen { // log!("Timeline::handle_event(): changed_indices: {changed_indices:?}, items len: {}\ncontent drawn: {:#?}\nprofile drawn: {:#?}", items.len(), tl.content_drawn_since_last_update, tl.profile_drawn_since_last_update); } tl.items = new_items; + done_loading = true; } TimelineUpdate::TimelineStartReached => { log!("Timeline::handle_event(): timeline start reached for room {}", tl.room_id); tl.fully_paginated = true; - done_loading = true; } TimelineUpdate::PaginationIdle => { - done_loading = true; + top_space.set_visible(true); } TimelineUpdate::EventDetailsFetched {event_id, result } => { if let Err(_e) = result { @@ -1670,8 +1672,7 @@ impl RoomScreen { } if done_loading { - log!("TODO: hide topspace loading animation for room {}", tl.room_id); - // TODO FIXME: hide TopSpace loading animation, set it to invisible. + top_space.set_visible(false); } if num_updates > 0 { // log!("Applied {} timeline updates for room {}, redrawing with {} items...", num_updates, tl.room_id, tl.items.len()); @@ -1913,6 +1914,25 @@ impl RoomScreen { self.show_timeline(cx); self.label(id!(room_name)).set_text(&self.room_name); } + + /// Send Pagination Request when the scroll position is at the top + fn send_pagination_request_based_on_scroll_pos( + &mut self, + cx: &mut Cx, + actions: &ActionsBuf, + ) { + let portal_list = self.portal_list(id!(list)); + //stopped scrolling and when scroll position is at top + if portal_list.scrolled(actions) { + return; + } + + let Some(room_id) = self.room_id.as_ref() else { return }; + if portal_list.scroll_position() == 0.0 { + submit_async_request(MatrixRequest::PaginateRoomTimeline { room_id: room_id.clone(), num_events: 50, forwards: false}); + } + + } } impl RoomScreenRef { From bb93b3926637b9dd736e8487053eb2ddf8a2c742 Mon Sep 17 00:00:00 2001 From: alanpoon Date: Fri, 11 Oct 2024 15:12:09 +0800 Subject: [PATCH 2/2] cleanup --- src/home/room_screen.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 74cc8a51..4e675a13 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -1268,8 +1268,9 @@ impl Widget for RoomScreen { } } - // Handle sending any read receipts for the current logged-in user. + // Set visibility of loading message banner based of pagination logic self.send_pagination_request_based_on_scroll_pos(cx, actions); + // Handle sending any read receipts for the current logged-in user. self.send_user_read_receipts_based_on_scroll_pos(cx, actions); // Handle the cancel reply button being clicked.