Skip to content

Commit 23473f8

Browse files
committed
feat(ffi): expose SpaceService::subscribe_to_joined_spaces and SpaceServiceRoomList::paginate
1 parent 5b9a2fe commit 23473f8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

bindings/matrix-sdk-ffi/src/spaces.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ impl SpaceService {
4949
self.inner.joined_spaces().into_iter().map(Into::into).collect()
5050
}
5151

52+
pub fn subscribe_to_joined_spaces(&self, listener: Box<dyn SpaceServiceJoinedSpacesListener>) {
53+
let entries_stream = self.inner.subscribe_to_joined_spaces();
54+
55+
Arc::new(TaskHandle::new(get_runtime_handle().spawn(async move {
56+
pin_mut!(entries_stream);
57+
58+
while let Some(rooms) = entries_stream.next().await {
59+
listener.on_update(rooms.into_iter().map(Into::into).collect());
60+
}
61+
})));
62+
}
63+
5264
#[allow(clippy::unused_async)]
5365
// This method doesn't need to be async but if its not the FFI layer panics
5466
// with "there is no no reactor running, must be called from the context
@@ -110,6 +122,10 @@ impl SpaceServiceRoomList {
110122
}
111123
})));
112124
}
125+
126+
pub async fn paginate(&self) -> Result<(), ClientError> {
127+
self.inner.paginate().await.map_err(ClientError::from)
128+
}
113129
}
114130

115131
#[derive(uniffi::Enum)]
@@ -143,6 +159,11 @@ pub trait SpaceServiceRoomListEntriesListener: SendOutsideWasm + SyncOutsideWasm
143159
fn on_update(&self, rooms: Vec<SpaceServiceRoom>);
144160
}
145161

162+
#[matrix_sdk_ffi_macros::export(callback_interface)]
163+
pub trait SpaceServiceJoinedSpacesListener: SendOutsideWasm + SyncOutsideWasm + Debug {
164+
fn on_update(&self, rooms: Vec<SpaceServiceRoom>);
165+
}
166+
146167
#[derive(uniffi::Record)]
147168
pub struct SpaceServiceRoom {
148169
pub room_id: String,

0 commit comments

Comments
 (0)