Skip to content

Commit 7718f90

Browse files
authored
event cache: add support for running back-pagination (#3195)
This adds support for back-pagination into the event cache, supporting enough features for integrating with the timeline (which is going to happen in a separate PR). The idea is to provide two new primitives: - one to get (or wait, if we don't have any handy) the latest pagination token received by the sync, - one to run a single back-pagination, given a token (or not — which will backpaginate from the end of the room's timeline) The timeline code can then use those two primitives in a loop to replicate the current behavior it has (next PR to be open Soon™). The representation of events in the store is changed, so that a timeline can have *entries*, which are one of two things: - either an event, as before - or a gap, identified by a backpagination token (at the moment) This allows us to avoid a lot of complexity from the back-pagination code in the timeline, where we'd attach the backpagination token to an event that only had an event_id. We don't have to do this here, and I suppose we could even attach the backpagination token to the next event itself. This doesn't do reconciliation yet; the plan is to add it as a next step.
1 parent 5e10ccc commit 7718f90

File tree

6 files changed

+1107
-66
lines changed

6 files changed

+1107
-66
lines changed

crates/matrix-sdk-ui/src/room_list_service/room.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,10 @@ impl Room {
168168
.add_initial_events(
169169
self.inner.room.room_id(),
170170
self.inner.sliding_sync_room.timeline_queue().iter().cloned().collect(),
171+
self.inner.sliding_sync_room.prev_batch(),
171172
)
172173
.await?;
173174

174-
Ok(Timeline::builder(&self.inner.room)
175-
.with_pagination_token(self.inner.sliding_sync_room.prev_batch())
176-
.track_read_marker_and_receipts())
175+
Ok(Timeline::builder(&self.inner.room).track_read_marker_and_receipts())
177176
}
178177
}

crates/matrix-sdk-ui/src/timeline/tests/pagination.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use super::TestTimeline;
2222
use crate::timeline::{inner::HandleBackPaginatedEventsError, pagination::PaginationTokens};
2323

2424
#[async_test]
25-
async fn back_pagination_token_not_updated_with_empty_chunk() {
25+
async fn test_back_pagination_token_not_updated_with_empty_chunk() {
2626
let timeline = TestTimeline::new();
2727

2828
timeline
@@ -65,7 +65,7 @@ async fn back_pagination_token_not_updated_with_empty_chunk() {
6565
}
6666

6767
#[async_test]
68-
async fn back_pagination_token_not_updated_invalid_event() {
68+
async fn test_back_pagination_token_not_updated_invalid_event() {
6969
let timeline = TestTimeline::new();
7070

7171
// Invalid empty event.

crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,14 @@ async fn timeline_test_helper(
258258
// TODO: when the event cache handles its own cache, we can remove this.
259259
client
260260
.event_cache()
261-
.add_initial_events(room_id, sliding_sync_room.timeline_queue().iter().cloned().collect())
261+
.add_initial_events(
262+
room_id,
263+
sliding_sync_room.timeline_queue().iter().cloned().collect(),
264+
sliding_sync_room.prev_batch(),
265+
)
262266
.await?;
263267

264-
let timeline = Timeline::builder(&sdk_room)
265-
.with_pagination_token(sliding_sync_room.prev_batch())
266-
.track_read_marker_and_receipts()
267-
.build()
268-
.await?;
268+
let timeline = Timeline::builder(&sdk_room).track_read_marker_and_receipts().build().await?;
269269

270270
Ok(timeline.subscribe().await)
271271
}

0 commit comments

Comments
 (0)