Skip to content

Commit

Permalink
refactor: Remove RoomEventCacheUpdate::AddTimelineEvents.
Browse files Browse the repository at this point in the history
This patch removes the `AddTimelineEvents` variant from
`RoomEventCacheUpdate` since it is replaced by `UpdateTimelineEvents`
which shares `VectorDiff`.

This patch also tests all uses of `UpdateTimelineEvents` in existing
tests.
  • Loading branch information
Hywan committed Jan 8, 2025
1 parent 5347af9 commit 493da24
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 108 deletions.
17 changes: 0 additions & 17 deletions crates/matrix-sdk-ui/src/timeline/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,23 +290,6 @@ impl TimelineBuilder {
inner.clear().await;
}

// TODO: remove once `UpdateTimelineEvents` is stabilized.
RoomEventCacheUpdate::AddTimelineEvents { events, origin } => {
if !settings_vectordiffs_as_inputs {
trace!("Received new timeline events.");

inner.add_events_at(
events.into_iter(),
TimelineNewItemPosition::End {
origin: match origin {
EventsOrigin::Sync => RemoteEventOrigin::Sync,
EventsOrigin::Pagination => RemoteEventOrigin::Pagination,
}
}
).await;
}
}

RoomEventCacheUpdate::UpdateTimelineEvents { diffs, origin } => {
if settings_vectordiffs_as_inputs {
trace!("Received new timeline events diffs");
Expand Down
10 changes: 0 additions & 10 deletions crates/matrix-sdk/src/event_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,16 +662,6 @@ pub enum RoomEventCacheUpdate {
ambiguity_changes: BTreeMap<OwnedEventId, AmbiguityChange>,
},

/// The room has received new timeline events.
// TODO: remove once `UpdateTimelineEvents` is stabilized
AddTimelineEvents {
/// All the new events that have been added to the room's timeline.
events: Vec<SyncTimelineEvent>,

/// Where the events are coming from.
origin: EventsOrigin,
},

/// The room has received updates for the timeline as _diffs_.
UpdateTimelineEvents {
/// Diffs to apply to the timeline.
Expand Down
7 changes: 4 additions & 3 deletions crates/matrix-sdk/src/event_cache/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ impl RoomPagination {
None
};

// The new prev token from this pagination.
let new_gap = paginator.prev_batch_token().map(|prev_token| Gap { prev_token });

let (backpagination_outcome, updates_as_vector_diffs) = state
let (backpagination_outcome, sync_timeline_events_diffs) = state
.with_events_mut(move |room_events| {
// Note: The chunk could be empty.
//
Expand Down Expand Up @@ -231,9 +232,9 @@ impl RoomPagination {
})
.await?;

if !updates_as_vector_diffs.is_empty() {
if !sync_timeline_events_diffs.is_empty() {
let _ = self.inner.sender.send(RoomEventCacheUpdate::UpdateTimelineEvents {
diffs: updates_as_vector_diffs,
diffs: sync_timeline_events_diffs,
origin: EventsOrigin::Pagination,
});
}
Expand Down
19 changes: 5 additions & 14 deletions crates/matrix-sdk/src/event_cache/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,12 @@ impl RoomEventCacheInner {

let mut all_events = self.all_events.write().await;

for sync_timeline_event in &sync_timeline_events {
for sync_timeline_event in sync_timeline_events {
if let Some(event_id) = sync_timeline_event.event_id() {
all_events.append_related_event(sync_timeline_event);
all_events.events.insert(
event_id.to_owned(),
(self.room_id.clone(), sync_timeline_event.clone()),
);
all_events.append_related_event(&sync_timeline_event);
all_events
.events
.insert(event_id.to_owned(), (self.room_id.clone(), sync_timeline_event));
}
}

Expand All @@ -471,14 +470,6 @@ impl RoomEventCacheInner {

// The order of `RoomEventCacheUpdate`s is **really** important here.
{
// TODO: remove once `UpdateTimelineEvents` is stabilized.
if !sync_timeline_events.is_empty() {
let _ = self.sender.send(RoomEventCacheUpdate::AddTimelineEvents {
events: sync_timeline_events,
origin: EventsOrigin::Sync,
});
}

if !sync_timeline_events_diffs.is_empty() {
let _ = self.sender.send(RoomEventCacheUpdate::UpdateTimelineEvents {
diffs: sync_timeline_events_diffs,
Expand Down
Loading

0 comments on commit 493da24

Please sign in to comment.