From 97a5fbebfb11517bc165b9f1b61ba318c61eeb9e Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 11 Aug 2025 12:21:33 +0300 Subject: [PATCH] feat(ffi): expose `SpaceService::subscribe_to_joined_spaces` and `SpaceServiceRoomList::paginate` --- bindings/matrix-sdk-ffi/src/spaces.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bindings/matrix-sdk-ffi/src/spaces.rs b/bindings/matrix-sdk-ffi/src/spaces.rs index 25cdfd3c1..3e1a4ff5a 100644 --- a/bindings/matrix-sdk-ffi/src/spaces.rs +++ b/bindings/matrix-sdk-ffi/src/spaces.rs @@ -49,6 +49,18 @@ impl SpaceService { self.inner.joined_spaces().into_iter().map(Into::into).collect() } + pub fn subscribe_to_joined_spaces(&self, listener: Box) { + let entries_stream = self.inner.subscribe_to_joined_spaces(); + + Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move { + pin_mut!(entries_stream); + + while let Some(rooms) = entries_stream.next().await { + listener.on_update(rooms.into_iter().map(Into::into).collect()); + } + }))); + } + #[allow(clippy::unused_async)] // This method doesn't need to be async but if its not the FFI layer panics // with "there is no no reactor running, must be called from the context @@ -110,6 +122,10 @@ impl SpaceServiceRoomList { } }))); } + + pub async fn paginate(&self) -> Result<(), ClientError> { + self.inner.paginate().await.map_err(ClientError::from) + } } #[derive(uniffi::Enum)] @@ -143,6 +159,11 @@ pub trait SpaceServiceRoomListEntriesListener: SendOutsideWasm + SyncOutsideWasm fn on_update(&self, rooms: Vec); } +#[matrix_sdk_ffi_macros::export(callback_interface)] +pub trait SpaceServiceJoinedSpacesListener: SendOutsideWasm + SyncOutsideWasm + Debug { + fn on_update(&self, rooms: Vec); +} + #[derive(uniffi::Record)] pub struct SpaceServiceRoom { pub room_id: String,