Skip to content

Commit

Permalink
feat(ui): room_list::RoomInner holds Arc to Timeline.
Browse files Browse the repository at this point in the history
This patch updates `RoomInner::timeline` and `::sneaky_timeline` to
`AsyncOnceCell<Arc<Timeline>>`. Adding `Arc` allows to copy the timeline
if necessary more easily.
  • Loading branch information
Hywan committed Jun 15, 2023
1 parent b9c27b5 commit 23d5655
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions crates/matrix-sdk-ui/src/room_list/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ struct RoomInner {
room: matrix_sdk::room::Room,

/// The timeline of the room.
timeline: AsyncOnceCell<Timeline>,
timeline: AsyncOnceCell<Arc<Timeline>>,

/// The “sneaky” timeline of the room, i.e. this timeline doesn't track the
/// read marker nor the receipts.
sneaky_timeline: AsyncOnceCell<Timeline>,
sneaky_timeline: AsyncOnceCell<Arc<Timeline>>,
}

impl Room {
Expand Down Expand Up @@ -98,20 +98,23 @@ impl Room {
}

/// Get the timeline of the room.
pub async fn timeline(&self) -> &Timeline {
pub async fn timeline(&self) -> Arc<Timeline> {
self.inner
.timeline
.get_or_init(async {
Timeline::builder(&self.inner.room)
.events(
self.inner.sliding_sync_room.prev_batch(),
self.inner.sliding_sync_room.timeline_queue(),
)
.track_read_marker_and_receipts()
.build()
.await
Arc::new(
Timeline::builder(&self.inner.room)
.events(
self.inner.sliding_sync_room.prev_batch(),
self.inner.sliding_sync_room.timeline_queue(),
)
.track_read_marker_and_receipts()
.build()
.await,
)
})
.await
.clone()
}

/// Get the latest event of the timeline.
Expand All @@ -122,13 +125,15 @@ impl Room {
self.inner
.sneaky_timeline
.get_or_init(async {
Timeline::builder(&self.inner.room)
.events(
self.inner.sliding_sync_room.prev_batch(),
self.inner.sliding_sync_room.timeline_queue(),
)
.build()
.await
Arc::new(
Timeline::builder(&self.inner.room)
.events(
self.inner.sliding_sync_room.prev_batch(),
self.inner.sliding_sync_room.timeline_queue(),
)
.build()
.await,
)
})
.await
.latest_event()
Expand Down

0 comments on commit 23d5655

Please sign in to comment.