Skip to content

Commit 1c1ecf0

Browse files
committed
ui: inline SlidingSyncRoomExt::timeline into its own caller
It's only used in test code, so it's not worth exposing to the SlidingSyncRoom object (and the Room already has such a timeline function, if needs be).
1 parent fd26cbc commit 1c1ecf0

File tree

4 files changed

+25
-42
lines changed

4 files changed

+25
-42
lines changed

crates/matrix-sdk-ui/src/timeline/builder.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ impl TimelineBuilder {
5757
}
5858

5959
/// Add initial events to the timeline.
60+
///
6061
/// TODO: remove this, the EventGraph should hold the events data in the
6162
/// first place, and we'd provide an existing EventGraph to the
6263
/// TimelineBuilder.
63-
pub(crate) async fn events(
64+
pub async fn events(
6465
mut self,
6566
prev_token: Option<String>,
6667
events: Vector<SyncTimelineEvent>,
@@ -75,7 +76,7 @@ impl TimelineBuilder {
7576

7677
/// Enable tracking of the fully-read marker and the read receipts on the
7778
/// timeline.
78-
pub(crate) fn track_read_marker_and_receipts(mut self) -> Self {
79+
pub fn track_read_marker_and_receipts(mut self) -> Self {
7980
self.settings.track_read_receipts = true;
8081
self
8182
}

crates/matrix-sdk-ui/src/timeline/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ impl From<&Annotation> for AnnotationKey {
144144
}
145145

146146
impl Timeline {
147-
pub(crate) fn builder(room: &Room) -> TimelineBuilder {
147+
/// Create a new [`TimelineBuilder`] for the given room.
148+
pub fn builder(room: &Room) -> TimelineBuilder {
148149
TimelineBuilder::new(room)
149150
}
150151

crates/matrix-sdk-ui/src/timeline/sliding_sync_ext.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@
1414

1515
use async_trait::async_trait;
1616
use matrix_sdk::SlidingSyncRoom;
17-
use tracing::{error, instrument};
17+
use tracing::instrument;
1818

19-
use super::{EventTimelineItem, Timeline, TimelineBuilder};
20-
use crate::event_graph::Result;
19+
use super::EventTimelineItem;
2120

2221
#[async_trait]
2322
pub trait SlidingSyncRoomExt {
24-
/// Get a `Timeline` for this room.
25-
// TODO(bnjbvr): remove from this trait.
26-
async fn timeline(&self) -> Result<Option<Timeline>>;
27-
2823
/// Get the latest timeline item of this room, if it is already cached.
2924
///
3025
/// Use `Timeline::latest_event` instead if you already have a timeline for
@@ -34,14 +29,6 @@ pub trait SlidingSyncRoomExt {
3429

3530
#[async_trait]
3631
impl SlidingSyncRoomExt for SlidingSyncRoom {
37-
async fn timeline(&self) -> Result<Option<Timeline>> {
38-
if let Some(builder) = sliding_sync_timeline_builder(self).await {
39-
Ok(Some(builder.track_read_marker_and_receipts().build().await?))
40-
} else {
41-
Ok(None)
42-
}
43-
}
44-
4532
/// Get a timeline item representing the latest event in this room.
4633
/// This method wraps latest_event, converting the event into an
4734
/// EventTimelineItem.
@@ -52,19 +39,6 @@ impl SlidingSyncRoomExt for SlidingSyncRoom {
5239
}
5340
}
5441

55-
async fn sliding_sync_timeline_builder(room: &SlidingSyncRoom) -> Option<TimelineBuilder> {
56-
let room_id = room.room_id();
57-
match room.client().get_room(room_id) {
58-
Some(r) => {
59-
Some(Timeline::builder(&r).events(room.prev_batch(), room.timeline_queue()).await)
60-
}
61-
None => {
62-
error!(?room_id, "Room not found in client. Can't provide a timeline for it");
63-
None
64-
}
65-
}
66-
}
67-
6842
#[cfg(test)]
6943
mod tests {
7044
use assert_matches::assert_matches;

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use std::{pin::Pin, sync::Arc};
1616

17-
use anyhow::{Context, Result};
17+
use anyhow::{Context as _, Result};
1818
use assert_matches::assert_matches;
1919
use assert_matches2::assert_let;
2020
use eyeball_im::{Vector, VectorDiff};
@@ -23,8 +23,9 @@ use matrix_sdk::{
2323
SlidingSync, SlidingSyncList, SlidingSyncListBuilder, SlidingSyncMode, UpdateSummary,
2424
};
2525
use matrix_sdk_test::async_test;
26-
use matrix_sdk_ui::timeline::{
27-
SlidingSyncRoomExt, TimelineItem, TimelineItemKind, VirtualTimelineItem,
26+
use matrix_sdk_ui::{
27+
timeline::{TimelineItem, TimelineItemKind, VirtualTimelineItem},
28+
Timeline,
2829
};
2930
use ruma::{room_id, user_id, RoomId};
3031
use serde_json::json;
@@ -248,15 +249,21 @@ async fn timeline_test_helper(
248249
sliding_sync: &SlidingSync,
249250
room_id: &RoomId,
250251
) -> Result<(Vector<Arc<TimelineItem>>, impl Stream<Item = VectorDiff<Arc<TimelineItem>>>)> {
251-
Ok(sliding_sync
252-
.get_room(room_id)
252+
let sliding_sync_room = sliding_sync.get_room(room_id).await.unwrap();
253+
254+
let room_id = sliding_sync_room.room_id();
255+
let sdk_room = sliding_sync_room.client().get_room(room_id).ok_or_else(|| {
256+
anyhow::anyhow!("Room {room_id} not found in client. Can't provide a timeline for it")
257+
})?;
258+
259+
let timeline = Timeline::builder(&sdk_room)
260+
.events(sliding_sync_room.prev_batch(), sliding_sync_room.timeline_queue())
253261
.await
254-
.unwrap()
255-
.timeline()
256-
.await?
257-
.context("`timeline`")?
258-
.subscribe()
259-
.await)
262+
.track_read_marker_and_receipts()
263+
.build()
264+
.await?;
265+
266+
Ok(timeline.subscribe().await)
260267
}
261268

262269
struct SlidingSyncMatcher;

0 commit comments

Comments
 (0)