From 4e92738c28ab24fed5d6056e9348fc59a9976c65 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 15 Jun 2023 13:48:41 +0200 Subject: [PATCH] feat(ui): Implement `RoomList::entries_loading_state`. This patch implements `RoomList::entries_loading_state`, which is a basic forwarding from the `all_rooms` sliding sync list' `state_stream()` result. --- crates/matrix-sdk-ui/src/room_list/mod.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/matrix-sdk-ui/src/room_list/mod.rs b/crates/matrix-sdk-ui/src/room_list/mod.rs index 552d275c5..483df7fd7 100644 --- a/crates/matrix-sdk-ui/src/room_list/mod.rs +++ b/crates/matrix-sdk-ui/src/room_list/mod.rs @@ -73,7 +73,7 @@ use imbl::Vector; pub use matrix_sdk::RoomListEntry; use matrix_sdk::{ sliding_sync::Ranges, Client, Error as SlidingSyncError, SlidingSync, SlidingSyncList, - SlidingSyncMode, + SlidingSyncListLoadingState, SlidingSyncMode, }; pub use room::*; use ruma::{ @@ -215,6 +215,21 @@ impl RoomList { .ok_or_else(|| Error::UnknownList(ALL_ROOMS_LIST_NAME.to_owned())) } + /// Get the entries loading state. + /// + /// It's a different state than [`State`]. It's also different than + /// [`Self::entries`] which subscribes to room entries updates. + /// + /// This method is used to subscribe to “loading state” + pub async fn entries_loading_state( + &self, + ) -> Result<(EntriesLoadingState, impl Stream), Error> { + self.sliding_sync + .on_list(ALL_ROOMS_LIST_NAME, |list| ready(list.state_stream())) + .await + .ok_or_else(|| Error::UnknownList(ALL_ROOMS_LIST_NAME.to_owned())) + } + /// Pass an [`Input`] onto the state machine. pub async fn apply_input(&self, input: Input) -> Result<(), Error> { use Input::*; @@ -289,6 +304,9 @@ 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};