From 39590c4e07721bb1897bec0c26b8dab0b36f7929 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 4 May 2023 14:50:53 +0200 Subject: [PATCH] chore(sdk): Re-order methods on `SlidingSyncRoom`. --- crates/matrix-sdk/src/sliding_sync/room.rs | 67 +++++++++++----------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/crates/matrix-sdk/src/sliding_sync/room.rs b/crates/matrix-sdk/src/sliding_sync/room.rs index a497f121e..9831b60ec 100644 --- a/crates/matrix-sdk/src/sliding_sync/room.rs +++ b/crates/matrix-sdk/src/sliding_sync/room.rs @@ -57,6 +57,7 @@ pub enum SlidingSyncRoomState { } impl SlidingSyncRoom { + /// Create a new `SlidingSyncRoom`. pub(super) fn new( client: Client, room_id: OwnedRoomId, @@ -72,43 +73,11 @@ impl SlidingSyncRoom { } } - /// RoomId of this SlidingSyncRoom + /// Get the room ID of this `SlidingSyncRoom`. pub fn room_id(&self) -> &OwnedRoomId { &self.room_id } - /// `Timeline` of this room - pub async fn timeline(&self) -> Option { - Some(self.timeline_builder()?.track_read_marker_and_receipts().build().await) - } - - fn timeline_builder(&self) -> Option { - if let Some(room) = self.client.get_room(&self.room_id) { - Some( - Timeline::builder(&room) - .events(self.inner.prev_batch.clone(), self.timeline_queue.clone()), - ) - } else if let Some(invited_room) = self.client.get_invited_room(&self.room_id) { - Some(Timeline::builder(&invited_room).events(None, Vector::new())) - } else { - error!( - room_id = ?self.room_id, - "Room not found in client. Can't provide a timeline for it" - ); - - None - } - } - - /// The latest timeline item of this room. - /// - /// Use `Timeline::latest_event` instead if you already have a timeline for - /// this `SlidingSyncRoom`. - #[instrument(skip_all)] - pub async fn latest_event(&self) -> Option { - self.timeline_builder()?.build().await.latest_event().await - } - /// This rooms name as calculated by the server, if any pub fn name(&self) -> Option<&str> { self.inner.name.as_deref() @@ -139,6 +108,38 @@ impl SlidingSyncRoom { &self.inner.required_state } + /// `Timeline` of this room + pub async fn timeline(&self) -> Option { + Some(self.timeline_builder()?.track_read_marker_and_receipts().build().await) + } + + /// The latest timeline item of this room. + /// + /// Use `Timeline::latest_event` instead if you already have a timeline for + /// this `SlidingSyncRoom`. + #[instrument(skip_all)] + pub async fn latest_event(&self) -> Option { + self.timeline_builder()?.build().await.latest_event().await + } + + fn timeline_builder(&self) -> Option { + if let Some(room) = self.client.get_room(&self.room_id) { + Some( + Timeline::builder(&room) + .events(self.inner.prev_batch.clone(), self.timeline_queue.clone()), + ) + } else if let Some(invited_room) = self.client.get_invited_room(&self.room_id) { + Some(Timeline::builder(&invited_room).events(None, Vector::new())) + } else { + error!( + room_id = ?self.room_id, + "Room not found in client. Can't provide a timeline for it" + ); + + None + } + } + pub(super) fn update( &mut self, room_data: v4::SlidingSyncRoom,