Skip to content

Commit

Permalink
refactor(ui): Timeline receives pagination events as VectorDiffs!
Browse files Browse the repository at this point in the history
This patch allows the paginated events of a `Timeline` to be received
via `RoomEventCacheUpdate::UpdateTimelineEvents` as `VectorDiff`s.
  • Loading branch information
Hywan committed Dec 17, 2024
1 parent e27b2b3 commit c44c178
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/matrix-sdk-ui/src/timeline/controller/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub(super) struct TimelineController<P: RoomDataProvider = Room> {
pub(crate) room_data_provider: P,

/// Settings applied to this timeline.
settings: TimelineSettings,
pub(super) settings: TimelineSettings,
}

#[derive(Clone)]
Expand Down
16 changes: 10 additions & 6 deletions crates/matrix-sdk-ui/src/timeline/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ impl super::Timeline {
let num_events = events.len();
trace!("Back-pagination succeeded with {num_events} events");

// TODO(hywan): Remove, and let spread events via
// `matrix_sdk::event_cache::RoomEventCacheUpdate` from
// `matrix_sdk::event_cache::RoomPagination::run_backwards`.
self.controller
.add_events_at(events.into_iter(), TimelineNewItemPosition::Start { origin: RemoteEventOrigin::Pagination })
.await;
// If `TimelineSettings::vectordiffs_as_inputs` is enabled,
// we don't need to add events manually: everything we need
// is to let the `EventCache` receives the events from this
// pagination, and emits its updates as `VectorDiff`s, which
// will be handled by the `Timeline` naturally.
if !self.controller.settings.vectordiffs_as_inputs {
self.controller
.add_events_at(events.into_iter(), TimelineNewItemPosition::Start { origin: RemoteEventOrigin::Pagination })
.await;
}

if num_events == 0 && !reached_start {
// As an exceptional contract: if there were no events in the response,
Expand Down

0 comments on commit c44c178

Please sign in to comment.