pub struct SpaceRoomList { /* private fields */ }Expand description
The SpaceRoomListrepresents a paginated list of direct rooms
that belong to a particular space.
It can be used to paginate through the list (and have live updates on the pagination state) as well as subscribe to changes as rooms are joined or left.
The SpaceRoomList also automatically subscribes to client room changes
and updates the list accordingly as rooms are joined or left.
§Examples
use futures_util::StreamExt;
use matrix_sdk::Client;
use matrix_sdk_ui::spaces::{
SpaceService, room_list::SpaceRoomListPaginationState,
};
use ruma::owned_room_id;
let space_service = SpaceService::new(client.clone()).await;
// Get a list of all the rooms in a particular space
let room_list = space_service
.space_room_list(owned_room_id!("!some_space:example.org"))
.await;
// Start off with an empty and idle list
room_list.rooms().is_empty();
assert_eq!(
room_list.pagination_state(),
SpaceRoomListPaginationState::Idle { end_reached: false }
);
// Subscribe to pagination state updates
let pagination_state_stream =
room_list.subscribe_to_pagination_state_updates();
// And to room list updates
let (_, room_stream) = room_list.subscribe_to_room_updates();
// Run this in a background task so it doesn't block
while let Some(pagination_state) = pagination_state_stream.next().await {
println!("Received pagination state update: {pagination_state:?}");
}
// Run this in a background task so it doesn't block
while let Some(diffs) = room_stream.next().await {
println!("Received room list update: {diffs:?}");
}
// Ask the room to load the next page
room_list.paginate().await.unwrap();
// And, if successful, rooms are available
let rooms = room_list.rooms();Implementations§
Source§impl SpaceRoomList
impl SpaceRoomList
Sourcepub async fn new(client: Client, space_id: OwnedRoomId) -> Self
pub async fn new(client: Client, space_id: OwnedRoomId) -> Self
Creates a new SpaceRoomList for the given space identifier.
Sourcepub fn subscribe_to_space_updates(&self) -> Subscriber<Option<SpaceRoom>>
pub fn subscribe_to_space_updates(&self) -> Subscriber<Option<SpaceRoom>>
Subscribe to space updates.
Sourcepub fn pagination_state(&self) -> SpaceRoomListPaginationState
pub fn pagination_state(&self) -> SpaceRoomListPaginationState
Returns if the room list is currently paginating or not.
Sourcepub fn subscribe_to_pagination_state_updates(
&self,
) -> Subscriber<SpaceRoomListPaginationState>
pub fn subscribe_to_pagination_state_updates( &self, ) -> Subscriber<SpaceRoomListPaginationState>
Subscribe to pagination updates.
Sourcepub fn subscribe_to_room_updates(
&self,
) -> (Vector<SpaceRoom>, VectorSubscriberBatchedStream<SpaceRoom>)
pub fn subscribe_to_room_updates( &self, ) -> (Vector<SpaceRoom>, VectorSubscriberBatchedStream<SpaceRoom>)
Subscribes to room list updates.
Sourcepub async fn paginate(&self) -> Result<(), Error>
pub async fn paginate(&self) -> Result<(), Error>
Ask the list to retrieve the next page if the end hasn’t been reached yet. Otherwise it no-ops.
Sourcepub async fn reset(&self)
pub async fn reset(&self)
Clears the room list back to its initial state so that any new changes
to the hierarchy will be included the next time Self::paginate is
called.
This is useful when you’ve added or removed children from the space as the list is based on a cached state that lives server-side, meaning the /hierarchy request needs to be restarted from scratch to pick up the changes.
Auto Trait Implementations§
impl !Freeze for SpaceRoomList
impl !RefUnwindSafe for SpaceRoomList
impl Send for SpaceRoomList
impl Sync for SpaceRoomList
impl Unpin for SpaceRoomList
impl !UnwindSafe for SpaceRoomList
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CompatExt for T
impl<T> CompatExt for T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more