diff --git a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs index 42e70eba3e1..29cd9fdd380 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs @@ -1529,7 +1529,7 @@ impl TimelineController { /// it's folded into another timeline item. pub(crate) async fn latest_event_id(&self) -> Option { let state = self.state.read().await; - state.meta.all_events.back().map(|event_meta| &event_meta.event_id).cloned() + state.meta.all_remote_events.back().map(|event_meta| &event_meta.event_id).cloned() } } diff --git a/crates/matrix-sdk-ui/src/timeline/controller/state.rs b/crates/matrix-sdk-ui/src/timeline/controller/state.rs index dd4ca784f5d..d8a26daa53c 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/state.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/state.rs @@ -601,7 +601,7 @@ impl TimelineStateTransaction<'_> { read_receipts: if settings.track_read_receipts && should_add { self.meta.read_receipts.compute_event_receipts( &event_id, - &self.meta.all_events, + &self.meta.all_remote_events, matches!(position, TimelineItemPosition::End { .. }), ) } else { @@ -678,8 +678,8 @@ impl TimelineStateTransaction<'_> { items.commit(); } - /// Add or update an event in the [`TimelineMetadata::all_events`] - /// collection. + /// Add or update a remote event in the + /// [`TimelineMetadata::all_remote_events`] collection. /// /// This method also adjusts read receipt if needed. /// @@ -693,38 +693,43 @@ impl TimelineStateTransaction<'_> { room_data_provider: &P, settings: &TimelineSettings, ) -> bool { - // Detect if an event already exists in [`TimelineMetadata::all_events`]. + // Detect if an event already exists in [`TimelineMetadata::all_remote_events`]. // // Returns its position, in this case. fn event_already_exists( new_event_id: &EventId, - all_events: &VecDeque, + all_remote_events: &VecDeque, ) -> Option { - all_events.iter().position(|EventMeta { event_id, .. }| event_id == new_event_id) + all_remote_events.iter().position(|EventMeta { event_id, .. }| event_id == new_event_id) } match position { TimelineItemPosition::Start { .. } => { - if let Some(pos) = event_already_exists(event_meta.event_id, &self.meta.all_events) + if let Some(pos) = + event_already_exists(event_meta.event_id, &self.meta.all_remote_events) { - self.meta.all_events.remove(pos); + self.meta.all_remote_events.remove(pos); } - self.meta.all_events.push_front(event_meta.base_meta()) + self.meta.all_remote_events.push_front(event_meta.base_meta()) } TimelineItemPosition::End { .. } => { - if let Some(pos) = event_already_exists(event_meta.event_id, &self.meta.all_events) + if let Some(pos) = + event_already_exists(event_meta.event_id, &self.meta.all_remote_events) { - self.meta.all_events.remove(pos); + self.meta.all_remote_events.remove(pos); } - self.meta.all_events.push_back(event_meta.base_meta()); + self.meta.all_remote_events.push_back(event_meta.base_meta()); } TimelineItemPosition::UpdateDecrypted { .. } => { - if let Some(event) = - self.meta.all_events.iter_mut().find(|e| e.event_id == event_meta.event_id) + if let Some(event) = self + .meta + .all_remote_events + .iter_mut() + .find(|e| e.event_id == event_meta.event_id) { if event.visible != event_meta.visible { event.visible = event_meta.visible; @@ -899,9 +904,9 @@ pub(in crate::timeline) struct TimelineMetadata { /// the device has terabytes of RAM. next_internal_id: u64, - /// List of all the events as received in the timeline, even the ones that - /// are discarded in the timeline items. - pub all_events: VecDeque, + /// List of all the remote events as received in the timeline, even the ones + /// that are discarded in the timeline items. + pub all_remote_events: VecDeque, /// State helping matching reactions to their associated events, and /// stashing pending reactions. @@ -945,7 +950,7 @@ impl TimelineMetadata { ) -> Self { Self { own_user_id, - all_events: Default::default(), + all_remote_events: Default::default(), next_internal_id: Default::default(), reactions: Default::default(), pending_poll_events: Default::default(), @@ -965,7 +970,7 @@ impl TimelineMetadata { pub(crate) fn clear(&mut self) { // Note: we don't clear the next internal id to avoid bad cases of stale unique // ids across timeline clears. - self.all_events.clear(); + self.all_remote_events.clear(); self.reactions.clear(); self.pending_poll_events.clear(); self.pending_edits.clear(); @@ -993,7 +998,7 @@ impl TimelineMetadata { // We can make early returns here because we know all events since the end of // the timeline, so the first event encountered is the oldest one. - for meta in self.all_events.iter().rev() { + for meta in self.all_remote_events.iter().rev() { if meta.event_id == event_a { return Some(RelativePosition::Before); } diff --git a/crates/matrix-sdk-ui/src/timeline/read_receipts.rs b/crates/matrix-sdk-ui/src/timeline/read_receipts.rs index 4287877670a..a97cbdc9340 100644 --- a/crates/matrix-sdk-ui/src/timeline/read_receipts.rs +++ b/crates/matrix-sdk-ui/src/timeline/read_receipts.rs @@ -390,7 +390,7 @@ impl TimelineStateTransaction<'_> { self.meta.read_receipts.maybe_update_read_receipt( full_receipt, is_own_user_id, - &self.meta.all_events, + &self.meta.all_remote_events, &mut self.items, ); } @@ -425,7 +425,7 @@ impl TimelineStateTransaction<'_> { self.meta.read_receipts.maybe_update_read_receipt( full_receipt, user_id == own_user_id, - &self.meta.all_events, + &self.meta.all_remote_events, &mut self.items, ); } @@ -454,7 +454,7 @@ impl TimelineStateTransaction<'_> { self.meta.read_receipts.maybe_update_read_receipt( full_receipt, is_own_event, - &self.meta.all_events, + &self.meta.all_remote_events, &mut self.items, ); } @@ -465,7 +465,7 @@ impl TimelineStateTransaction<'_> { // Find the previous visible event, if there is one. let Some(prev_event_meta) = self .meta - .all_events + .all_remote_events .iter() .rev() // Find the event item. @@ -495,7 +495,7 @@ impl TimelineStateTransaction<'_> { let read_receipts = self.meta.read_receipts.compute_event_receipts( &remote_prev_event_item.event_id, - &self.meta.all_events, + &self.meta.all_remote_events, false, ); @@ -585,7 +585,7 @@ impl TimelineState { // Find the corresponding visible event. self.meta - .all_events + .all_remote_events .iter() .rev() .skip_while(|ev| ev.event_id != *latest_receipt_id)