Browse Source

timeline: Expose method to know if we can load more events

fractal-6
Kévin Commaille 3 years ago
parent
commit
4d778e8dfe
No known key found for this signature in database
GPG Key ID: 29A48C1F03620416
  1. 21
      src/session/model/room/timeline/mod.rs
  2. 5
      src/session/view/content/room_history/mod.rs

21
src/session/model/room/timeline/mod.rs

@ -358,16 +358,21 @@ impl Timeline {
}
}
/// Whether it's possible to load more events with the current state of the
/// timeline.
pub fn can_load(&self) -> bool {
// We don't want to load twice at the same time, and it's useless to try to load
// more history before the timeline is ready or when we reached the
// start.
!matches!(
self.state(),
TimelineState::Initial | TimelineState::Loading | TimelineState::Complete
)
}
/// Load events at the start of the timeline.
pub async fn load(&self) {
let state = self.state();
if matches!(
state,
TimelineState::Initial | TimelineState::Loading | TimelineState::Complete
) {
// We don't want to load twice at the same time, and it's useless to try to load
// more history before the timeline is ready or when we reached the
// start.
if !self.can_load() {
return;
}

5
src/session/view/content/room_history/mod.rs

@ -1070,10 +1070,7 @@ impl RoomHistory {
};
let timeline = room.timeline();
if matches!(
timeline.state(),
TimelineState::Initial | TimelineState::Loading
) {
if !timeline.can_load() {
// We will retry when the timeline is ready.
return;
}

Loading…
Cancel
Save