From c44c1780254804753fd702a9ad47f7a8bad1e776 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 17 Dec 2024 17:30:44 +0100 Subject: [PATCH] refactor(ui): `Timeline` receives pagination events as `VectorDiff`s! This patch allows the paginated events of a `Timeline` to be received via `RoomEventCacheUpdate::UpdateTimelineEvents` as `VectorDiff`s. --- .../matrix-sdk-ui/src/timeline/controller/mod.rs | 2 +- crates/matrix-sdk-ui/src/timeline/pagination.rs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs index 13dc36bc6e9..3fbbc32a87e 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs @@ -124,7 +124,7 @@ pub(super) struct TimelineController { pub(crate) room_data_provider: P, /// Settings applied to this timeline. - settings: TimelineSettings, + pub(super) settings: TimelineSettings, } #[derive(Clone)] diff --git a/crates/matrix-sdk-ui/src/timeline/pagination.rs b/crates/matrix-sdk-ui/src/timeline/pagination.rs index abe49acac0f..cc4e3e7a0ef 100644 --- a/crates/matrix-sdk-ui/src/timeline/pagination.rs +++ b/crates/matrix-sdk-ui/src/timeline/pagination.rs @@ -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,