mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-19 06:04:31 -04:00
feat(sdk): Add LinkedChunk::first_chunk.
This patch adds `LinkedChunk::first_chunk`, and exposes it to `EventLinkedChunk` to replace the use of 2 iterators in `RoomPagination` and `ThreadPagination`, and to remove 2 `unwrap`s.
This commit is contained in:
@@ -1110,6 +1110,11 @@ impl<const CAP: usize, Item, Gap> LinkedChunk<CAP, Item, Gap> {
|
||||
.skip(position.index()))
|
||||
}
|
||||
|
||||
/// Return the first chunk.
|
||||
pub fn first_chunk(&self) -> &Chunk<CAP, Item, Gap> {
|
||||
self.links.first_chunk()
|
||||
}
|
||||
|
||||
/// Get a mutable reference to the `LinkedChunk` updates, aka
|
||||
/// [`ObservableUpdates`].
|
||||
///
|
||||
|
||||
@@ -177,6 +177,11 @@ impl EventLinkedChunk {
|
||||
self.chunks.chunk_identifier(predicate)
|
||||
}
|
||||
|
||||
/// Return the first chunk.
|
||||
pub fn first_chunk(&self) -> &Chunk<DEFAULT_CHUNK_CAPACITY, Event, Gap> {
|
||||
self.chunks.first_chunk()
|
||||
}
|
||||
|
||||
/// Iterate over the chunks, forward.
|
||||
///
|
||||
/// The oldest chunk comes first.
|
||||
|
||||
@@ -170,8 +170,7 @@ impl PaginatedCache for Arc<RoomEventCacheInner> {
|
||||
});
|
||||
}
|
||||
|
||||
let prev_first_chunk =
|
||||
state.room_linked_chunk().chunks().next().expect("a linked chunk is never empty");
|
||||
let prev_first_chunk = state.room_linked_chunk().first_chunk();
|
||||
|
||||
// The first chunk is not a gap, we can load its previous chunk.
|
||||
let linked_chunk_id = LinkedChunkId::Room(&state.state.room_id);
|
||||
|
||||
@@ -112,8 +112,7 @@ impl PaginatedCache for ThreadEventCacheWrapper {
|
||||
});
|
||||
}
|
||||
|
||||
let prev_first_chunk =
|
||||
state.thread_linked_chunk().chunks().next().expect("a linked chunk is never empty");
|
||||
let prev_first_chunk = state.thread_linked_chunk().first_chunk();
|
||||
|
||||
// The first chunk is not a gap, we can load its previous chunk.
|
||||
let linked_chunk_id = LinkedChunkId::Thread(&state.room_id, &state.thread_id);
|
||||
|
||||
Reference in New Issue
Block a user