Skip to content

Commit

Permalink
chore(ui): Remove impl Add for HandleManyEventsResult.
Browse files Browse the repository at this point in the history
This patch inlines the `Add` implementation for `HandleManyEventsResult`
since it's used only once.
  • Loading branch information
Hywan committed Jun 10, 2024
1 parent 26fa7f2 commit 2077ecd
Showing 1 changed file with 47 additions and 56 deletions.
103 changes: 47 additions & 56 deletions crates/matrix-sdk-ui/src/timeline/inner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -587,54 +587,56 @@ impl<P: RoomDataProvider> TimelineInner<P> {
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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2077ecd

Please sign in to comment.