Skip to content

Commit

Permalink
feat(ui): Implement RoomList::entries_loading_state.
Browse files Browse the repository at this point in the history
This patch implements `RoomList::entries_loading_state`, which
is a basic forwarding from the `all_rooms` sliding sync list'
`state_stream()` result.
  • Loading branch information
Hywan committed Jun 15, 2023
1 parent db67983 commit 4e92738
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion crates/matrix-sdk-ui/src/room_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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<Item = EntriesLoadingState>), 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::*;
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 4e92738

Please sign in to comment.