Skip to main content

SpaceService

Struct SpaceService 

Source
pub struct SpaceService { /* private fields */ }
Expand description

The main entry point into the Spaces facilities.

The spaces service is responsible for retrieving one’s joined rooms, building a graph out of their m.space.parent and m.space.child state events, and providing access to the top-level spaces and their children.

§Examples

use futures_util::StreamExt;
use matrix_sdk::Client;
use matrix_sdk_ui::spaces::SpaceService;
use ruma::owned_room_id;

let space_service = SpaceService::new(client.clone()).await;

// Get a list of all the joined spaces
let joined_spaces = space_service.top_level_joined_spaces().await;

// And subscribe to changes on them
// `initial_values` is equal to `top_level_joined_spaces` if nothing changed meanwhile
let (initial_values, stream) =
    space_service.subscribe_to_top_level_joined_spaces().await;

while let Some(diffs) = stream.next().await {
    println!("Received joined spaces updates: {diffs:?}");
}

// 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;

// Which can be used to retrieve information about the children rooms
let children = room_list.rooms().await;

Implementations§

Source§

impl SpaceService

Source

pub async fn new(client: Client) -> Self

Creates a new SpaceService instance.

Source

pub async fn subscribe_to_top_level_joined_spaces( &self, ) -> (Vector<SpaceRoom>, VectorSubscriberBatchedStream<SpaceRoom>)

Subscribes to updates on the joined spaces list. If space rooms are joined or left, the stream will yield diffs that reflect the changes.

Source

pub async fn top_level_joined_spaces(&self) -> Vec<SpaceRoom>

Returns a list of all the top-level joined spaces. It will eagerly compute the latest version and also notify subscribers if there were any changes.

Source

pub async fn space_filters(&self) -> Vec<SpaceFilter>

Space filters provide access to a custom subset of the space graph that can be used in tandem with the crate::RoomListService to narrow down the presented rooms. A crate::room_list_service::RoomList’s crate::room_list_service::RoomListDynamicEntriesController can take a filter, which in this case can be a crate::room_list_service::filters::new_filter_identifiers pointing to the space descendants retrieved from the filters.

They are limited to the first 2 levels of the graph, with the first level only containing direct descendants while the second holds the rest of them recursively.

§Examples
use futures_util::StreamExt;
use matrix_sdk::Client;
use matrix_sdk_ui::{
    room_list_service::{RoomListService, filters},
    spaces::SpaceService,
};
use ruma::owned_room_id;

let space_service = SpaceService::new(client.clone()).await;
let room_list_service = RoomListService::new(client.clone()).await?;

// Get the list of filters derived from the space hierarchy.
let space_filters = space_service.space_filters().await;
// Pick a filter/space
let space_filter = space_filters.first().unwrap();

// Create a room list stream and a controller that accepts filters.
let all_rooms = room_list_service.all_rooms().await?;
let (_, controller) = all_rooms.entries_with_dynamic_adapters(25);

// Apply an identifiers filter built from the space filter descendants.
controller.set_filter(Box::new(filters::new_filter_identifiers(
    space_filter.descendants.clone(),
)));
Source

pub async fn subscribe_to_space_filters( &self, ) -> (Vector<SpaceFilter>, VectorSubscriberBatchedStream<SpaceFilter>)

Subscribe to changes or updates to the space filters.

Source

pub async fn editable_spaces(&self) -> Vec<SpaceRoom>

Returns a flattened list containing all the spaces where the user has permission to send m.space.child state events.

Note: Unlike Self::top_level_joined_spaces(), this method does not recompute graph, nor does it notify subscribers about changes.

Source

pub async fn space_room_list(&self, space_id: OwnedRoomId) -> SpaceRoomList

Returns a SpaceRoomList for the given space ID.

Source

pub async fn joined_parents_of_child(&self, child_id: &RoomId) -> Vec<SpaceRoom>

Returns all known direct-parents of a given space room ID.

Source

pub async fn joined_parent_ids_of_child( &self, child_id: &RoomId, ) -> Vec<OwnedRoomId>

Returns the room IDs of all known direct parents of the given child space or room.

This is a much cheaper version of Self::joined_parents_of_child() that doesn’t build any SpaceRoom instances, it only reads the existing space graph.

The returned IDs are always joined spaces, as that’s all the space graph includes. Note that an empty result either means that the child is a top-level space (which has no direct parents) or the child isn’t part of the space graph at all. See Self::top_level_ancestors_of() if you need that particular level of detail.

Note: Unlike Self::top_level_joined_spaces(), this method does not recompute the space graph nor notify subscribers about changes.

Source

pub async fn top_level_ancestors_of( &self, child_id: &RoomId, ) -> HashSet<OwnedRoomId>

Returns the room IDs of the top-level joined space(s) that the given child room/space descends from, by walking the space graph upwards.

A room/space can be the child of multiple spaces, so this might return multiple top-level spaces (in no order).

A top-level space is its own only ancestor, so a returned set holding just child_id is a cheap top-level space check.

Returns an empty set if the room isn’t part of the graph, which is notably the case for a room that was joined too recently for the graph to have been rebuilt.

Note: Unlike Self::top_level_joined_spaces(), this method does not recompute the space graph nor notify subscribers about changes.

Source

pub async fn get_space_room(&self, room_id: &RoomId) -> Option<SpaceRoom>

Returns the corresponding SpaceRoom for the given room ID, or None if it isn’t known.

Source

pub async fn add_child_to_space( &self, child_id: OwnedRoomId, space_id: OwnedRoomId, ) -> Result<(), Error>

Source

pub async fn remove_child_from_space( &self, child_id: OwnedRoomId, space_id: OwnedRoomId, ) -> Result<(), Error>

Source

pub async fn leave_space( &self, space_id: &RoomId, ) -> Result<LeaveSpaceHandle, Error>

Start a space leave process returning a LeaveSpaceHandle from which rooms can be retrieved in reversed BFS order starting from the requested space_id graph node. If the room is unknown then an error will be returned.

Once the rooms to be left are chosen the handle can be used to leave them.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DropFlavorWrapper<T> for T

Source§

type Flavor = MayDrop

The DropFlavor that wraps T into Self
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> JsonCastable<CanonicalJsonValue> for T

Source§

impl<T> JsonCastable<Value> for T

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SendOutsideWasm for T
where T: Send,

Source§

impl<T> SyncOutsideWasm for T
where T: Sync,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more