Skip to content

Commit a453080

Browse files
committed
feat(sdk): Find and remove duplicated events in RoomEvents.
This patch uses the new `Deduplicator` type, along with `LinkeChunk::remove_item_at` to remove duplicated events. When a new event is received, the older one is removed.
1 parent b1aa46b commit a453080

File tree

2 files changed

+512
-22
lines changed

2 files changed

+512
-22
lines changed

crates/matrix-sdk/src/event_cache/linked_chunk/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,18 @@ impl Position {
948948
pub fn index(&self) -> usize {
949949
self.1
950950
}
951+
952+
/// Move the index part (see [`Self::index`]) to the left, i.e. subtract 1.
953+
///
954+
/// # Panic
955+
///
956+
/// This method will panic if it will overflow, i.e. if the index is 0.
957+
pub(super) fn move_index_to_the_left(&mut self) {
958+
self.1 = self
959+
.1
960+
.checked_sub(1)
961+
.expect("Cannot move position's index to the left because it's already 0");
962+
}
951963
}
952964

953965
/// An iterator over a [`LinkedChunk`] that traverses the chunk in backward

0 commit comments

Comments
 (0)