From 2a70587dda736490e789c070c8f12ca123f2803e Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 5 Jun 2024 16:43:43 +0200 Subject: [PATCH] chore(ui): Make `TimelineInnerMetadata::next_internal_id` private. This patch updates `TimelineEventHandler` to re-use the public API and avoid using `TimelineInnerMeta::next_internal_id`. The consequence is that `next_internal_id` can now be private instead of public. It's better to have isolated API in this code. --- crates/matrix-sdk-ui/src/timeline/event_handler.rs | 10 ++++------ crates/matrix-sdk-ui/src/timeline/inner/state.rs | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/event_handler.rs b/crates/matrix-sdk-ui/src/timeline/event_handler.rs index ee67e1e3c..c7b5f5290 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_handler.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_handler.rs @@ -1005,17 +1005,15 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { // pending local echo, or at the start if there is no such item. let insert_idx = latest_event_idx.map_or(0, |idx| idx + 1); - let id = match removed_event_item_id { + trace!("Adding new remote timeline item after all non-pending events"); + let new_item = match removed_event_item_id { // If a previous version of the same item (usually a local // echo) was removed and we now need to add it again, reuse // the previous item's ID. - Some(id) => id, - None => self.meta.next_internal_id(), + Some(id) => TimelineItem::new(item, id), + None => self.meta.new_timeline_item(item), }; - trace!("Adding new remote timeline item after all non-pending events"); - let new_item = TimelineItem::new(item, id); - // Keep push semantics, if we're inserting at the front or the back. if insert_idx == self.items.len() { self.items.push_back(new_item); diff --git a/crates/matrix-sdk-ui/src/timeline/inner/state.rs b/crates/matrix-sdk-ui/src/timeline/inner/state.rs index e07648f7f..6b728acac 100644 --- a/crates/matrix-sdk-ui/src/timeline/inner/state.rs +++ b/crates/matrix-sdk-ui/src/timeline/inner/state.rs @@ -788,7 +788,7 @@ impl TimelineInnerMetadata { /// Returns the next internal id for a timeline item (and increment our /// internal counter). - pub fn next_internal_id(&mut self) -> String { + fn next_internal_id(&mut self) -> String { let val = self.next_internal_id; self.next_internal_id += 1; let prefix = self.internal_id_prefix.as_deref().unwrap_or("");