From f79a581f4084226bc9cd541fb4d184400c169064 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 10 Jun 2024 13:34:36 +0200 Subject: [PATCH] chore(ui): Remove impl `Add` for `HandleManyEventsResult`. This patch inlines the `Add` implementation for `HandleManyEventsResult` since it's used only once. --- .../matrix-sdk-ui/src/timeline/inner/mod.rs | 103 ++++++++---------- 1 file changed, 47 insertions(+), 56 deletions(-) diff --git a/crates/matrix-sdk-ui/src/timeline/inner/mod.rs b/crates/matrix-sdk-ui/src/timeline/inner/mod.rs index d33332ffc40..09e4556f9eb 100644 --- a/crates/matrix-sdk-ui/src/timeline/inner/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/inner/mod.rs @@ -14,7 +14,7 @@ #[cfg(feature = "e2e-encryption")] use std::collections::BTreeSet; -use std::{fmt, ops::Add, sync::Arc}; +use std::{fmt, sync::Arc}; use as_variant::as_variant; use eyeball_im::{ObservableVectorEntry, VectorDiff}; @@ -587,54 +587,56 @@ impl TimelineInner

{ let mut state = self.state.write().await; for diff in diffs { - result = result - + match diff { - VectorDiff::Append { values: events } => { - state - .add_remote_events_at( - events, - TimelineNewItemPosition::End { origin }, - room_data_provider, - settings, - ) - .await - } + let HandleManyEventsResult { items_added, items_updated } = match diff { + VectorDiff::Append { values: events } => { + state + .add_remote_events_at( + events, + TimelineNewItemPosition::End { origin }, + room_data_provider, + settings, + ) + .await + } - VectorDiff::PushFront { value } => { - state - .add_remote_events_at( - [value], - TimelineNewItemPosition::Start { origin }, - room_data_provider, - settings, - ) - .await - } + VectorDiff::PushFront { value } => { + state + .add_remote_events_at( + [value], + TimelineNewItemPosition::Start { origin }, + room_data_provider, + settings, + ) + .await + } - VectorDiff::PushBack { value } => { - state - .add_remote_events_at( - [value], - TimelineNewItemPosition::End { origin }, - room_data_provider, - settings, - ) - .await - } + VectorDiff::PushBack { value } => { + state + .add_remote_events_at( + [value], + TimelineNewItemPosition::End { origin }, + room_data_provider, + settings, + ) + .await + } - VectorDiff::Insert { index: event_index, value } => { - state - .add_remote_events_at( - [value], - TimelineNewItemPosition::At { event_index, origin }, - room_data_provider, - settings, - ) - .await - } + VectorDiff::Insert { index: event_index, value } => { + state + .add_remote_events_at( + [value], + TimelineNewItemPosition::At { event_index, origin }, + room_data_provider, + settings, + ) + .await + } - diff => unimplemented!("Unsupported `VectorDiff` {diff:?}"), - }; + diff => unimplemented!("Unsupported `VectorDiff` {diff:?}"), + }; + + result.items_added = items_added; + result.items_updated = items_updated; } result @@ -1315,17 +1317,6 @@ pub(super) struct HandleManyEventsResult { pub items_updated: u64, } -impl Add for HandleManyEventsResult { - type Output = Self; - - fn add(self, other: Self) -> Self { - Self { - items_added: self.items_added + other.items_added, - items_updated: self.items_updated + other.items_updated, - } - } -} - async fn fetch_replied_to_event( mut state: RwLockWriteGuard<'_, TimelineInnerState>, index: usize,