Skip to content

Commit

Permalink
feat(sdk): Find and remove duplicated events in RoomEvents.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Hywan committed Oct 28, 2024
1 parent b04c21b commit f621c8c
Show file tree
Hide file tree
Showing 2 changed files with 512 additions and 22 deletions.
12 changes: 12 additions & 0 deletions crates/matrix-sdk/src/event_cache/linked_chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,18 @@ impl Position {
pub fn index(&self) -> usize {
self.1
}

/// Move the index part (see [`Self::index`]) to the left, i.e. subtract 1.
///
/// # Panic
///
/// This method will panic if it will overflow, i.e. if the index is 0.
pub(super) fn move_index_to_the_left(&mut self) {
self.1 = self
.1
.checked_sub(1)
.expect("Cannot move position's index to the left because it's already 0");
}
}

/// An iterator over a [`LinkedChunk`] that traverses the chunk in backward
Expand Down
Loading

0 comments on commit f621c8c

Please sign in to comment.