7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | // Copyright 2025 The Matrix.org Foundation C.I.C. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | // you may not use this file except in compliance with the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | // You may obtain a copy of the License at |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | // Unless required by applicable law or agreed to in writing, software |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | // See the License for the specific language governing permissions and |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | // limitations under the License. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | use std::{fmt::Debug, sync::Arc}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | use eyeball_im::VectorDiff; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | use futures_util::{StreamExt, pin_mut}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | use matrix_sdk_common::{SendOutsideWasm, SyncOutsideWasm}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | use matrix_sdk_ui::spaces::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | SpaceFilter as UISpaceFilter, SpaceRoom as UISpaceRoom, SpaceRoomList as UISpaceRoomList, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | SpaceService as UISpaceService, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | leave::{LeaveSpaceHandle as UILeaveSpaceHandle, LeaveSpaceRoom as UILeaveSpaceRoom}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | room_list::SpaceRoomListPaginationState, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | use ruma::RoomId; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | use crate::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | TaskHandle, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | client::JoinRule, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | error::ClientError, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | room::{Membership, RoomHero}, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | room_preview::RoomType, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | runtime::get_runtime_handle, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | /// The main entry point into the Spaces facilities. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | /// The spaces service is responsible for retrieving one's joined rooms, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | /// building a graph out of their `m.space.parent` and `m.space.child` state |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | /// events, and providing access to the top-level spaces and their children. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | #[derive(uniffi::Object)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | pub struct SpaceService { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | inner: UISpaceService, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 45 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 46 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 47 | impl SpaceService { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 48 | /// Creates a new `SpaceService` instance. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 49 | pub(crate) fn new(inner: UISpaceService) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 50 | Self { inner } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 51 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 52 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 53 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 54 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 55 | impl SpaceService { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 56 | /// Returns a list of all the top-level joined spaces. It will eagerly |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 57 | /// compute the latest version and also notify subscribers if there were |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 58 | /// any changes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 59 | pub async fn top_level_joined_spaces(&self) -> Vec<SpaceRoom> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 60 | self.inner.top_level_joined_spaces().await.into_iter().map(Into::into).collect() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 61 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 62 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 63 | /// Subscribes to updates on the joined spaces list. If space rooms are |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 64 | /// joined or left, the stream will yield diffs that reflect the changes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 65 | pub async fn subscribe_to_top_level_joined_spaces( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 66 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 67 | listener: Box<dyn SpaceServiceJoinedSpacesListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 68 | ) -> Arc<TaskHandle> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 69 | let (initial_values, mut stream) = self.inner.subscribe_to_top_level_joined_spaces().await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 70 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 71 | listener.on_update(vec![SpaceListUpdate::Reset { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 72 | values: initial_values.into_iter().map(Into::into).collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 73 | }]); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 74 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 75 | Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 76 | while let Some(diffs) = stream.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 77 | listener.on_update(diffs.into_iter().map(Into::into).collect()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 78 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 79 | }))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 80 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 81 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 82 | /// Space filters provide access to a custom subset of the space graph that |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 83 | /// can be used in tandem with the [`crate::RoomListService`] to narrow |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 84 | /// down the presented rooms. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 85 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 86 | /// They are limited to the first 2 levels of the graph, with the first |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 87 | /// level only containing direct descendants while the second holds the rest |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 88 | /// of them recursively. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 89 | pub async fn space_filters(&self) -> Vec<SpaceFilter> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 90 | self.inner.space_filters().await.into_iter().map(|s| s.into()).collect() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 91 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 92 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 93 | /// Subscribe to changes or updates to the space filters. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 94 | pub async fn subscribe_to_space_filters( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 95 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 96 | listener: Box<dyn SpaceServiceSpaceFiltersListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 97 | ) -> Arc<TaskHandle> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 98 | let (initial_values, mut stream) = self.inner.subscribe_to_space_filters().await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 99 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 100 | listener.on_update(vec![SpaceFilterUpdate::Reset { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 101 | values: initial_values.into_iter().map(Into::into).collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 102 | }]); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 103 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 104 | Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 105 | while let Some(diffs) = stream.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 106 | listener.on_update(diffs.into_iter().map(Into::into).collect()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 107 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 108 | }))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 109 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 110 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 111 | /// Returns a flattened list containing all the spaces where the user has |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 112 | /// permission to send `m.space.child` state events. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 113 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 114 | /// Note: Unlike [`Self::top_level_joined_spaces()`], this method does not |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 115 | /// recompute the space graph, nor does it notify subscribers about changes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 116 | pub async fn editable_spaces(&self) -> Vec<SpaceRoom> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 117 | self.inner.editable_spaces().await.into_iter().map(Into::into).collect() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 118 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 119 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 120 | /// Returns a `SpaceRoomList` for the given space ID. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 121 | pub async fn space_room_list( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 122 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 123 | space_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 124 | ) -> Result<Arc<SpaceRoomList>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 125 | let space_id = RoomId::parse(space_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 126 | Ok(Arc::new(SpaceRoomList::new(self.inner.space_room_list(space_id).await))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 127 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 128 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 129 | /// Returns all known direct-parents of a given space room ID. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 130 | pub async fn joined_parents_of_child( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 131 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 132 | child_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 133 | ) -> Result<Vec<SpaceRoom>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 134 | let child_id = RoomId::parse(child_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 135 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 136 | let parents = self.inner.joined_parents_of_child(&child_id).await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 137 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 138 | Ok(parents.into_iter().map(Into::into).collect()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 139 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 140 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 141 | /// Returns the corresponding `SpaceRoom` for the given room ID, or `None` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 142 | /// if it isn't known. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 143 | pub async fn get_space_room(&self, room_id: String) -> Result<Option<SpaceRoom>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 144 | let room_id = RoomId::parse(room_id.as_str())?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 145 | Ok(self.inner.get_space_room(&room_id).await.map(Into::into)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 146 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 147 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 148 | pub async fn add_child_to_space( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 149 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 150 | child_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 151 | space_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 152 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 153 | let space_id = RoomId::parse(space_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 154 | let child_id = RoomId::parse(child_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 155 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 156 | self.inner.add_child_to_space(child_id, space_id).await.map_err(ClientError::from) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 157 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 158 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 159 | pub async fn remove_child_from_space( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 160 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 161 | child_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 162 | space_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 163 | ) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 164 | let space_id = RoomId::parse(space_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 165 | let child_id = RoomId::parse(child_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 166 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 167 | self.inner.remove_child_from_space(child_id, space_id).await.map_err(ClientError::from) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 168 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 169 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 170 | /// Start a space leave process returning a [`LeaveSpaceHandle`] from which |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 171 | /// rooms can be retrieved in reversed BFS order starting from the requested |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 172 | /// `space_id` graph node. If the room is unknown then an error will be |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 173 | /// returned. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 174 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 175 | /// Once the rooms to be left are chosen the handle can be used to leave |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 176 | /// them. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 177 | pub async fn leave_space( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 178 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 179 | space_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 180 | ) -> Result<Arc<LeaveSpaceHandle>, ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 181 | let space_id = RoomId::parse(space_id)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 182 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 183 | let handle = self.inner.leave_space(&space_id).await.map_err(ClientError::from)?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 184 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 185 | Ok(Arc::new(handle.into())) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 186 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 187 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 188 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 189 | /// The `SpaceRoomList` represents a paginated list of direct rooms |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 190 | /// that belong to a particular space. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 191 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 192 | /// It can be used to paginate through the list (and have live updates on the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 193 | /// pagination state) as well as subscribe to changes as rooms are joined or |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 194 | /// left. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 195 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 196 | /// The `SpaceRoomList` also automatically subscribes to client room changes |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 197 | /// and updates the list accordingly as rooms are joined or left. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 198 | #[derive(uniffi::Object)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 199 | pub struct SpaceRoomList { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 200 | inner: UISpaceRoomList, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 201 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 202 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 203 | impl SpaceRoomList { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 204 | /// Creates a new `SpaceRoomList` for the underlying UI crate room list. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 205 | fn new(inner: UISpaceRoomList) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 206 | Self { inner } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 207 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 208 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 209 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 210 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 211 | impl SpaceRoomList { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 212 | /// Returns the space of the room list if known. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 213 | pub fn space(&self) -> Option<SpaceRoom> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 214 | self.inner.space().map(Into::into) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 215 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 216 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 217 | /// Subscribe to space updates. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 218 | pub fn subscribe_to_space_updates( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 219 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 220 | listener: Box<dyn SpaceRoomListSpaceListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 221 | ) -> Arc<TaskHandle> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 222 | let space_updates = self.inner.subscribe_to_space_updates(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 223 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 224 | Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 225 | pin_mut!(space_updates); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 226 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 227 | while let Some(space) = space_updates.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 228 | listener.on_update(space.map(Into::into)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 229 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 230 | }))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 231 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 232 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 233 | /// Returns if the room list is currently paginating or not. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 234 | pub fn pagination_state(&self) -> SpaceRoomListPaginationState { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 235 | self.inner.pagination_state() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 236 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 237 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 238 | /// Subscribe to pagination updates. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 239 | pub fn subscribe_to_pagination_state_updates( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 240 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 241 | listener: Box<dyn SpaceRoomListPaginationStateListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 242 | ) -> Arc<TaskHandle> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 243 | let pagination_state = self.inner.subscribe_to_pagination_state_updates(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 244 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 245 | Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 246 | pin_mut!(pagination_state); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 247 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 248 | while let Some(state) = pagination_state.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 249 | listener.on_update(state); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 250 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 251 | }))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 252 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 253 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 254 | /// Return the current list of rooms. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 255 | pub async fn rooms(&self) -> Vec<SpaceRoom> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 256 | self.inner.rooms().await.into_iter().map(Into::into).collect() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 257 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 258 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 259 | /// Subscribes to room list updates. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 260 | pub async fn subscribe_to_room_update( |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 261 | &self, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 262 | listener: Box<dyn SpaceRoomListEntriesListener>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 263 | ) -> Arc<TaskHandle> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 264 | let (initial_values, mut stream) = self.inner.subscribe_to_room_updates().await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 265 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 266 | listener.on_update(vec![SpaceListUpdate::Reset { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 267 | values: initial_values.into_iter().map(Into::into).collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 268 | }]); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 269 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 270 | Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 271 | while let Some(diffs) = stream.next().await { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 272 | listener.on_update(diffs.into_iter().map(Into::into).collect()); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 273 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 274 | }))) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 275 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 276 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 277 | /// Ask the list to retrieve the next page if the end hasn't been reached |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 278 | /// yet. Otherwise it no-ops. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 279 | pub async fn paginate(&self) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 280 | self.inner.paginate().await.map_err(ClientError::from) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 281 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 282 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 283 | /// Clears the room list back to its initial state so that any new changes |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 284 | /// to the hierarchy will be included the next time [`Self::paginate`] is |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 285 | /// called. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 286 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 287 | /// This is useful when you've added or removed children from the space as |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 288 | /// the list is based on a cached state that lives server-side, meaning |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 289 | /// the /hierarchy request needs to be restarted from scratch to pick up |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 290 | /// the changes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 291 | pub async fn reset(&self) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 292 | self.inner.reset().await; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 293 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 294 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 295 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 296 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 297 | pub trait SpaceRoomListSpaceListener: SendOutsideWasm + SyncOutsideWasm + Debug { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 298 | fn on_update(&self, space: Option<SpaceRoom>); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 299 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 300 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 301 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 302 | pub trait SpaceRoomListPaginationStateListener: SendOutsideWasm + SyncOutsideWasm + Debug { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 303 | fn on_update(&self, pagination_state: SpaceRoomListPaginationState); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 304 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 305 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 306 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 307 | pub trait SpaceRoomListEntriesListener: SendOutsideWasm + SyncOutsideWasm + Debug { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 308 | fn on_update(&self, rooms: Vec<SpaceListUpdate>); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 309 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 310 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 311 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 312 | pub trait SpaceServiceJoinedSpacesListener: SendOutsideWasm + SyncOutsideWasm + Debug { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 313 | fn on_update(&self, room_updates: Vec<SpaceListUpdate>); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 314 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 315 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 316 | #[matrix_sdk_ffi_macros::export(callback_interface)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 317 | pub trait SpaceServiceSpaceFiltersListener: SendOutsideWasm + SyncOutsideWasm + Debug { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 318 | fn on_update(&self, filter_updates: Vec<SpaceFilterUpdate>); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 319 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 320 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 321 | /// Structure representing a room in a space and aggregated information |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 322 | /// relevant to the UI layer. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 323 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 324 | pub struct SpaceRoom { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 325 | /// The ID of the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 326 | pub room_id: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 327 | /// The canonical alias of the room, if any. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 328 | pub canonical_alias: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 329 | /// The room's name from the room state event if received from sync, or one |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 330 | /// that's been computed otherwise. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 331 | pub display_name: String, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 332 | /// Room name as defined by the room state event only. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 333 | pub raw_name: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 334 | /// The topic of the room, if any. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 335 | pub topic: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 336 | /// The URL for the room's avatar, if one is set. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 337 | pub avatar_url: Option<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 338 | /// The type of room from `m.room.create`, if any. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 339 | pub room_type: RoomType, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 340 | /// The number of members joined to the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 341 | pub num_joined_members: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 342 | /// The join rule of the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 343 | pub join_rule: Option<JoinRule>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 344 | /// Whether the room may be viewed by users without joining. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 345 | pub world_readable: Option<bool>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 346 | /// Whether guest users may join the room and participate in it. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 347 | pub guest_can_join: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 348 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 349 | /// Whether this room is a direct room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 350 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 351 | /// Only set if the room is known to the client otherwise we |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 352 | /// assume DMs shouldn't be exposed publicly in spaces. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 353 | pub is_direct: Option<bool>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 354 | /// The number of children room this has, if a space. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 355 | pub children_count: u64, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 356 | /// Whether this room is joined, left etc. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 357 | pub state: Option<Membership>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 358 | /// A list of room members considered to be heroes. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 359 | pub heroes: Option<Vec<RoomHero>>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 360 | /// The via parameters of the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 361 | pub via: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 362 | /// Whether this room is a DM, if known. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 363 | /// Note this value can be calculated following some assumptions and is not |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 364 | /// guaranteed to be accurate. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 365 | pub is_dm: Option<bool>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 366 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 367 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 368 | impl From<UISpaceRoom> for SpaceRoom { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 369 | fn from(room: UISpaceRoom) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 370 | Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 371 | room_id: room.room_id.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 372 | canonical_alias: room.canonical_alias.map(|alias| alias.into()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 373 | display_name: room.display_name, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 374 | raw_name: room.name, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 375 | topic: room.topic, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 376 | avatar_url: room.avatar_url.map(|url| url.into()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 377 | room_type: room.room_type.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 378 | num_joined_members: room.num_joined_members, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 379 | join_rule: room.join_rule.map(Into::into), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 380 | world_readable: room.world_readable, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 381 | guest_can_join: room.guest_can_join, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 382 | is_direct: room.is_direct, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 383 | children_count: room.children_count, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 384 | state: room.state.map(Into::into), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 385 | heroes: room.heroes.map(|heroes| heroes.into_iter().map(Into::into).collect()), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 386 | via: room.via.into_iter().map(Into::into).collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 387 | is_dm: room.is_dm, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 388 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 389 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 390 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 391 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 392 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 393 | pub enum SpaceListUpdate { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 394 | Append { values: Vec<SpaceRoom> }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 395 | Clear, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 396 | PushFront { value: SpaceRoom }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 397 | PushBack { value: SpaceRoom }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 398 | PopFront, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 399 | PopBack, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 400 | Insert { index: u32, value: SpaceRoom }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 401 | Set { index: u32, value: SpaceRoom }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 402 | Remove { index: u32 }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 403 | Truncate { length: u32 }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 404 | Reset { values: Vec<SpaceRoom> }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 405 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 406 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 407 | impl From<VectorDiff<UISpaceRoom>> for SpaceListUpdate { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 408 | fn from(diff: VectorDiff<UISpaceRoom>) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 409 | match diff { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 410 | VectorDiff::Append { values } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 411 | Self::Append { values: values.into_iter().map(|v| v.into()).collect() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 412 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 413 | VectorDiff::Clear => Self::Clear, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 414 | VectorDiff::PushFront { value } => Self::PushFront { value: value.into() }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 415 | VectorDiff::PushBack { value } => Self::PushBack { value: value.into() }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 416 | VectorDiff::PopFront => Self::PopFront, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 417 | VectorDiff::PopBack => Self::PopBack, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 418 | VectorDiff::Insert { index, value } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 419 | Self::Insert { index: index as u32, value: value.into() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 420 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 421 | VectorDiff::Set { index, value } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 422 | Self::Set { index: index as u32, value: value.into() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 423 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 424 | VectorDiff::Remove { index } => Self::Remove { index: index as u32 }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 425 | VectorDiff::Truncate { length } => Self::Truncate { length: length as u32 }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 426 | VectorDiff::Reset { values } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 427 | Self::Reset { values: values.into_iter().map(|v| v.into()).collect() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 428 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 429 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 430 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 431 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 432 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 433 | #[derive(uniffi::Enum)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 434 | pub enum SpaceFilterUpdate { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 435 | Append { values: Vec<SpaceFilter> }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 436 | Clear, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 437 | PushFront { value: SpaceFilter }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 438 | PushBack { value: SpaceFilter }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 439 | PopFront, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 440 | PopBack, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 441 | Insert { index: u32, value: SpaceFilter }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 442 | Set { index: u32, value: SpaceFilter }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 443 | Remove { index: u32 }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 444 | Truncate { length: u32 }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 445 | Reset { values: Vec<SpaceFilter> }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 446 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 447 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 448 | impl From<VectorDiff<UISpaceFilter>> for SpaceFilterUpdate { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 449 | fn from(diff: VectorDiff<UISpaceFilter>) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 450 | match diff { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 451 | VectorDiff::Append { values } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 452 | Self::Append { values: values.into_iter().map(|v| v.into()).collect() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 453 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 454 | VectorDiff::Clear => Self::Clear, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 455 | VectorDiff::PushFront { value } => Self::PushFront { value: value.into() }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 456 | VectorDiff::PushBack { value } => Self::PushBack { value: value.into() }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 457 | VectorDiff::PopFront => Self::PopFront, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 458 | VectorDiff::PopBack => Self::PopBack, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 459 | VectorDiff::Insert { index, value } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 460 | Self::Insert { index: index as u32, value: value.into() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 461 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 462 | VectorDiff::Set { index, value } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 463 | Self::Set { index: index as u32, value: value.into() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 464 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 465 | VectorDiff::Remove { index } => Self::Remove { index: index as u32 }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 466 | VectorDiff::Truncate { length } => Self::Truncate { length: length as u32 }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 467 | VectorDiff::Reset { values } => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 468 | Self::Reset { values: values.into_iter().map(|v| v.into()).collect() } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 469 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 470 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 471 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 472 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 473 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 474 | /// The `LeaveSpaceHandle` processes rooms to be left in the order they were |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 475 | /// provided by the [`SpaceService`] and annotates them with extra data to |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 476 | /// inform the leave process e.g. if the current user is the last room admin. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 477 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 478 | /// Once the upstream client decides what rooms should actually be left, the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 479 | /// handle provides a method to execute that too. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 480 | #[derive(uniffi::Object)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 481 | pub struct LeaveSpaceHandle { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 482 | inner: UILeaveSpaceHandle, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 483 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 484 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 485 | #[matrix_sdk_ffi_macros::export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 486 | impl LeaveSpaceHandle { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 487 | /// A list of rooms to be left which next to normal [`SpaceRoom`] data also |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 488 | /// include leave specific information. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 489 | pub fn rooms(&self) -> Vec<LeaveSpaceRoom> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 490 | let rooms = self.inner.rooms(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 491 | rooms.iter().map(|room| room.clone().into()).collect() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 492 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 493 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 494 | /// Bulk leave the given rooms. Stops when encountering an error. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 495 | pub async fn leave(&self, room_ids: Vec<String>) -> Result<(), ClientError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 496 | let room_ids = room_ids.iter().map(RoomId::parse).collect::<Result<Vec<_>, _>>()?; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 497 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 498 | self.inner |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 499 | .leave(|room| room_ids.contains(&room.space_room.room_id)) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 500 | .await |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 501 | .map_err(ClientError::from) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 502 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 503 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 504 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 505 | impl From<UILeaveSpaceHandle> for LeaveSpaceHandle { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 506 | fn from(handle: UILeaveSpaceHandle) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 507 | LeaveSpaceHandle { inner: handle } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 508 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 509 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 510 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 511 | /// Space leaving specific room that groups normal [`SpaceRoom`] details with |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 512 | /// information about the leaving user's role. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 513 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 514 | pub struct LeaveSpaceRoom { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 515 | /// The underlying [`SpaceRoom`] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 516 | pub space_room: SpaceRoom, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 517 | /// Whether the user is the last owner in the room. This helps clients |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 518 | /// better inform the user about the consequences of leaving the room. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 519 | pub is_last_owner: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 520 | /// If the room creators have infinite PL. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 521 | pub are_creators_privileged: bool, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 522 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 523 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 524 | impl From<UILeaveSpaceRoom> for LeaveSpaceRoom { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 525 | fn from(room: UILeaveSpaceRoom) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 526 | LeaveSpaceRoom { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 527 | space_room: room.space_room.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 528 | is_last_owner: room.is_last_owner, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 529 | are_creators_privileged: room.are_creators_privileged, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 530 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 531 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 532 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 533 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 534 | #[derive(uniffi::Record)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 535 | pub struct SpaceFilter { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 536 | /// The underlying [`SpaceRoom`] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 537 | space_room: SpaceRoom, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 538 | /// The level of the space filter in the tree/hierarchy. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 539 | /// At this point in time the filters are limited to the first 2 levels. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 540 | level: u8, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 541 | /// The room identifiers of the descendants of this space. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 542 | /// For top level spaces (level 0) these will be direct descendants while |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 543 | /// for first level spaces they will be all other descendants, recursively. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 544 | descendants: Vec<String>, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 545 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 546 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 547 | impl From<UISpaceFilter> for SpaceFilter { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 548 | fn from(filter: UISpaceFilter) -> Self { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 549 | SpaceFilter { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 550 | space_room: filter.space_room.into(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 551 | level: filter.level, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 552 | descendants: filter.descendants.into_iter().map(|id| id.to_string()).collect(), |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 553 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 554 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 555 | } |