Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backward Paginate timeline by scroll #109 #186

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,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 @@ -1529,6 +1531,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 @@ -1613,14 +1616,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);
alanpoon marked this conversation as resolved.
Show resolved Hide resolved
}
TimelineUpdate::EventDetailsFetched {event_id, result } => {
if let Err(_e) = result {
Expand Down Expand Up @@ -1670,8 +1673,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 @@ -1913,6 +1915,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;
}
alanpoon marked this conversation as resolved.
Show resolved Hide resolved

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