Skip to content

Commit

Permalink
Merge pull request #186 from alanpoon/paginate-timeline-by-scroll-#109
Browse files Browse the repository at this point in the history
Backward Paginate timeline by scroll #109
  • Loading branch information
kevinaboos authored Oct 11, 2024
2 parents 0e349be + cac4a04 commit 18237da
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@ impl Widget for RoomScreen {
}
}

// 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);

Expand Down Expand Up @@ -1520,6 +1522,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 };

Expand Down Expand Up @@ -1604,14 +1607,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 {
Expand Down Expand Up @@ -1661,8 +1664,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());
Expand Down Expand Up @@ -1904,6 +1906,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 {
Expand Down

0 comments on commit 18237da

Please sign in to comment.