From b5446391871fc2d3bae6821fe3044e596c0acf8e Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 23 Mar 2023 10:07:19 +0100 Subject: [PATCH] chore(sdk): Re-ordering methods inside `SlidingSyncList`. --- .../matrix-sdk/src/sliding_sync/list/mod.rs | 68 ++++++++----------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/crates/matrix-sdk/src/sliding_sync/list/mod.rs b/crates/matrix-sdk/src/sliding_sync/list/mod.rs index af15fbdc3..62cef4969 100644 --- a/crates/matrix-sdk/src/sliding_sync/list/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/list/mod.rs @@ -30,20 +30,6 @@ use crate::Result; /// Holding a specific filtered list within the concept of sliding sync. /// Main entrypoint to the `SlidingSync`: /// -/// ```no_run -/// # use futures::executor::block_on; -/// # use matrix_sdk::Client; -/// # use url::Url; -/// # block_on(async { -/// # let homeserver = Url::parse("http://example.com")?; -/// let client = Client::new(homeserver).await?; -/// let sliding_sync = -/// client.sliding_sync().await.add_fullsync_list().build().await?; -/// -/// # anyhow::Ok(()) -/// # }); -/// ``` -/// /// It is OK to clone this type as much as you need: cloning it is cheap. #[derive(Clone, Debug)] pub struct SlidingSyncList { @@ -51,33 +37,6 @@ pub struct SlidingSyncList { } impl SlidingSyncList { - /// Get the name of the list. - pub fn name(&self) -> &str { - self.inner.name.as_str() - } - - /// Calculate the next request and return it. - pub(super) fn next_request(&mut self) -> Option { - self.inner.next_request() - } - - pub(crate) fn set_from_cold( - &mut self, - maximum_number_of_rooms: Option, - rooms_list: Vector, - ) { - Observable::set(&mut self.inner.state.write().unwrap(), SlidingSyncState::Preloaded); - self.inner.is_cold.store(true, Ordering::SeqCst); - Observable::set( - &mut self.inner.maximum_number_of_rooms.write().unwrap(), - maximum_number_of_rooms, - ); - - let mut lock = self.inner.rooms_list.write().unwrap(); - lock.clear(); - lock.append(rooms_list); - } - /// Create a new [`SlidingSyncListBuilder`]. pub fn builder() -> SlidingSyncListBuilder { SlidingSyncListBuilder::new() @@ -105,6 +64,28 @@ impl SlidingSyncList { builder } + pub(crate) fn set_from_cold( + &mut self, + maximum_number_of_rooms: Option, + rooms_list: Vector, + ) { + Observable::set(&mut self.inner.state.write().unwrap(), SlidingSyncState::Preloaded); + self.inner.is_cold.store(true, Ordering::SeqCst); + Observable::set( + &mut self.inner.maximum_number_of_rooms.write().unwrap(), + maximum_number_of_rooms, + ); + + let mut lock = self.inner.rooms_list.write().unwrap(); + lock.clear(); + lock.append(rooms_list); + } + + /// Get the name of the list. + pub fn name(&self) -> &str { + self.inner.name.as_str() + } + /// Set the ranges to fetch. /// /// Remember to cancel the existing stream and fetch a new one as this will @@ -221,6 +202,11 @@ impl SlidingSyncList { .and_then(|room_list_entry| room_list_entry.as_room_id().map(ToOwned::to_owned)) } + /// Calculate the next request and return it. + pub(super) fn next_request(&mut self) -> Option { + self.inner.next_request() + } + // Handle the response from the server. #[instrument(skip(self, ops), fields(name = self.name(), ops_count = ops.len()))] pub(super) fn handle_response(