From c9e3d7988f478c1ea0984f97dd065e03ff71de2d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 22 Jun 2023 10:23:45 +0200 Subject: [PATCH] feat(ui): Change how `room_list::State` is updated. Instead of broadcasting an intermediate update for the `State`, it's updated once after the sync. --- crates/matrix-sdk-ui/src/room_list/mod.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/matrix-sdk-ui/src/room_list/mod.rs b/crates/matrix-sdk-ui/src/room_list/mod.rs index 3340b3869..7f932c311 100644 --- a/crates/matrix-sdk-ui/src/room_list/mod.rs +++ b/crates/matrix-sdk-ui/src/room_list/mod.rs @@ -74,7 +74,7 @@ use futures_util::{pin_mut, Stream, StreamExt}; pub use matrix_sdk::RoomListEntry; use matrix_sdk::{ sliding_sync::Ranges, Client, Error as SlidingSyncError, SlidingSync, SlidingSyncList, - SlidingSyncListLoadingState, SlidingSyncMode, + SlidingSyncMode, }; pub use room::*; pub use room_list::*; @@ -162,21 +162,24 @@ impl RoomListService { // // 1. The next state is calculated, // 2. The actions associated to the next state are run, - // 3. The next state is stored, - // 4. A sync is done. - // - // So the sync is done after the machine _has entered_ into a new state. + // 3. A sync is done, + // 4. The next state is stored. loop { + // Calculate the next state, and run the associated actions. let next_state = self.state.get().next(&self.sliding_sync).await?; - self.state.set(next_state); + // Do the sync. match sync.next().await { Some(Ok(_update_summary)) => { + // Update the state. + dbg!(&next_state); + self.state.set(next_state); + yield Ok(()); } Some(Err(error)) => { - let next_state = State::Error { from: Box::new(self.state.get()) }; + let next_state = State::Error { from: Box::new(next_state) }; self.state.set(next_state); yield Err(Error::SlidingSync(error)); @@ -185,7 +188,7 @@ impl RoomListService { } None => { - let next_state = State::Terminated { from: Box::new(self.state.get()) }; + let next_state = State::Terminated { from: Box::new(next_state) }; self.state.set(next_state); break; @@ -307,9 +310,6 @@ pub enum Input { Viewport(Ranges), } -/// Type alias for entries loading state. -pub type EntriesLoadingState = SlidingSyncListLoadingState; - #[cfg(test)] mod tests { use matrix_sdk::{config::RequestConfig, reqwest::Url, Session};