diff --git a/crates/matrix-sdk-ui/src/room_list_service/mod.rs b/crates/matrix-sdk-ui/src/room_list_service/mod.rs index bc726bae7..913d9643b 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/mod.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/mod.rs @@ -221,6 +221,7 @@ impl RoomListService { // Do the sync. match sync.next().await { + // Got a successful result while syncing. Some(Ok(_update_summary)) => { // Update the state. self.state.set(next_state); @@ -228,6 +229,7 @@ impl RoomListService { yield Ok(()); } + // Got an error while syncing. Some(Err(error)) => { let next_state = State::Error { from: Box::new(next_state) }; self.state.set(next_state); @@ -237,6 +239,7 @@ impl RoomListService { break; } + // Sync-loop has terminated. None => { let next_state = State::Terminated { from: Box::new(next_state) }; self.state.set(next_state); @@ -271,6 +274,26 @@ impl RoomListService { self.sliding_sync.stop_sync().map_err(Error::SlidingSync) } + /// Force the sliding sync session to expire. + /// + /// This is used by [`SyncService`][crate::SyncService]. + /// + /// **Warning**: This method **must** be called when the sync-loop isn't + /// running! + pub(crate) async fn expire_sync_session(&self) { + self.sliding_sync.expire_session().await; + + // Usually, when the session expires, it leads the state to be `Error`, + // thus some actions (like refreshing the lists) are executed. However, + // if the sync-loop has been stopped manually, the state is `Terminated`, and + // when the session is forced to expire, the state remains `Terminated`, thus + // the actions aren't executed as expected. Consequently, let's update the + // state. + if let State::Terminated { from } = self.state.get() { + self.state.set(State::Error { from }); + } + } + /// Get the [`Client`] that has been used to create [`Self`]. pub fn client(&self) -> &Client { &self.client @@ -348,10 +371,6 @@ impl RoomListService { Ok(room) } - pub(crate) async fn expire_sync_session(&self) { - self.sliding_sync.expire_session().await; - } - #[cfg(test)] pub fn sliding_sync(&self) -> &SlidingSync { &self.sliding_sync