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:
Ivan Enderlin
2026-04-28 11:04:06 +02:00
parent 5e3b98e714
commit cead90253e
4 changed files with 12 additions and 4 deletions

View File

@@ -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`].
///

View File

@@ -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.

View File

@@ -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);

View File

@@ -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);