diff --git a/crates/matrix-sdk/src/event_cache/store.rs b/crates/matrix-sdk/src/event_cache/store.rs index f5d12ae97e8..998b2b6557c 100644 --- a/crates/matrix-sdk/src/event_cache/store.rs +++ b/crates/matrix-sdk/src/event_cache/store.rs @@ -230,6 +230,11 @@ impl RoomEvents { Self { chunks: LinkedChunk::new() } } + /// Clear all events. + pub fn reset(&mut self) { + self.chunks = LinkedChunk::new(); + } + /// Return the number of events. pub fn len(&self) -> usize { self.chunks.len() @@ -251,6 +256,11 @@ impl RoomEvents { self.chunks.push_items_back(events) } + /// Push a gap after existing events. + pub fn push_gap(&mut self, gap: Gap) { + self.chunks.push_gap_back(gap) + } + /// Insert events at a specified position. pub fn insert_events_at( &mut self, @@ -273,6 +283,22 @@ impl RoomEvents { self.chunks.insert_gap_at(gap, position) } + /// Replace the gap identified by `gap_identifier`, by events. + /// + /// Because the `gap_identifier` can represent non-gap chunk, this method + /// returns a `Result`. + pub fn replace_gap_at( + &mut self, + items: I, + gap_identifier: ChunkIdentifier, + ) -> StdResult<(), LinkedChunkError> + where + I: IntoIterator, + I::IntoIter: ExactSizeIterator, + { + self.chunks.replace_gap_at(items, gap_identifier) + } + /// Search for a chunk, and return its identifier. pub fn chunk_identifier<'a, P>(&'a self, predicate: P) -> Option where @@ -328,6 +354,13 @@ impl RoomEvents { self.chunks.ritems() } + /// Iterate over the events, forward. + /// + /// The oldest event comes first. + pub fn events(&self) -> impl Iterator { + self.chunks.items() + } + /// Iterate over the events, starting from `position`, backward. pub fn revents_from( &self,