diff --git a/crates/matrix-sdk/src/event_cache/pagination.rs b/crates/matrix-sdk/src/event_cache/pagination.rs index 3c14f3dd34d..0d40c1046a0 100644 --- a/crates/matrix-sdk/src/event_cache/pagination.rs +++ b/crates/matrix-sdk/src/event_cache/pagination.rs @@ -167,7 +167,7 @@ impl RoomPagination { let new_gap = paginator.prev_batch_token().map(|prev_token| Gap { prev_token }); - let result = state + let (backpagination_outcome, updates_as_vector_diffs) = state .with_events_mut(move |room_events| { // Note: The chunk could be empty. // @@ -227,20 +227,18 @@ impl RoomPagination { debug!("not storing previous batch token, because we deduplicated all new back-paginated events"); } - let sync_timeline_events_diffs = room_events.updates_as_vector_diffs(); - - if !sync_timeline_events_diffs.is_empty() { - let _ = self.inner.sender.send(RoomEventCacheUpdate::UpdateTimelineEvents { - diffs: sync_timeline_events_diffs, - origin: EventsOrigin::Sync, - }); - } - BackPaginationOutcome { events, reached_start } }) .await?; - Ok(Some(result)) + if !updates_as_vector_diffs.is_empty() { + let _ = self.inner.sender.send(RoomEventCacheUpdate::UpdateTimelineEvents { + diffs: updates_as_vector_diffs, + origin: EventsOrigin::Sync, + }); + } + + Ok(Some(backpagination_outcome)) } /// Get the latest pagination token, as stored in the room events linked diff --git a/crates/matrix-sdk/src/event_cache/room/events.rs b/crates/matrix-sdk/src/event_cache/room/events.rs index bc7843ff9f0..eb352c99580 100644 --- a/crates/matrix-sdk/src/event_cache/room/events.rs +++ b/crates/matrix-sdk/src/event_cache/room/events.rs @@ -245,7 +245,6 @@ impl RoomEvents { /// See [`AsVector`] to learn more. /// /// [`Update`]: matrix_sdk_base::linked_chunk::Update - #[allow(unused)] // gonna be useful very soon! but we need it now for test purposes pub fn updates_as_vector_diffs(&mut self) -> Vec> { self.chunks_updates_as_vectordiffs.take() } diff --git a/crates/matrix-sdk/src/event_cache/room/mod.rs b/crates/matrix-sdk/src/event_cache/room/mod.rs index 93c30e7513c..b0efde1395d 100644 --- a/crates/matrix-sdk/src/event_cache/room/mod.rs +++ b/crates/matrix-sdk/src/event_cache/room/mod.rs @@ -534,7 +534,7 @@ impl RoomEventCacheInner { // Add the previous back-pagination token (if present), followed by the timeline // events themselves. let sync_timeline_events_diffs = { - let sync_timeline_events_diffs = state + let (_, sync_timeline_events_diffs) = state .with_events_mut(|room_events| { if let Some(prev_token) = &prev_batch { room_events.push_gap(Gap { prev_token: prev_token.clone() }); @@ -556,8 +556,6 @@ impl RoomEventCacheInner { .replace_gap_at([], prev_gap_id) .expect("we obtained the valid position beforehand"); } - - room_events.updates_as_vector_diffs() }) .await?; @@ -641,6 +639,7 @@ fn chunk_debug_string(content: &ChunkContent) -> String mod private { use std::sync::Arc; + use eyeball_im::VectorDiff; use matrix_sdk_base::{ deserialized_responses::{SyncTimelineEvent, TimelineEventKind}, event_cache::{ @@ -846,13 +845,18 @@ mod private { /// Gives a temporary mutable handle to the underlying in-memory events, /// and will propagate changes to the storage once done. + /// + /// Returns the output of the given callback, as well as updates to the + /// linked chunk, as vector diff, so the caller may propagate + /// such updates, if needs be. pub async fn with_events_mut O>( &mut self, func: F, - ) -> Result { + ) -> Result<(O, Vec>), EventCacheError> { let output = func(&mut self.events); self.propagate_changes().await?; - Ok(output) + let updates_as_vector_diffs = self.events.updates_as_vector_diffs(); + Ok((output, updates_as_vector_diffs)) } }