mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-10 00:48:44 -04:00
feat(ffi) Room::members returns a RoomMembersIterator.
This patch updates `Room::members` to return `Result<Arc<RoomMembersIterator>, ClientError>`. This `RoomMembersIterator` type is new, and is implemented in this patch too. The idea behind this patch is to allow the bindings to “paginate” over the list of members for a particular room, in case the room has 17k members for example.
This commit is contained in:
@@ -42,6 +42,7 @@ use uuid::Uuid;
|
||||
|
||||
use super::RUNTIME;
|
||||
use crate::{
|
||||
chunk_iterator::ChunkIterator,
|
||||
client::ProgressWatcher,
|
||||
error::{ClientError, RoomError},
|
||||
room_info::RoomInfo,
|
||||
@@ -197,14 +198,8 @@ impl Room {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn members(&self) -> Result<Vec<Arc<RoomMember>>, ClientError> {
|
||||
Ok(self
|
||||
.inner
|
||||
.members(RoomMemberships::empty())
|
||||
.await?
|
||||
.iter()
|
||||
.map(|m| Arc::new(RoomMember::new(m.clone())))
|
||||
.collect())
|
||||
pub async fn members(&self) -> Result<Arc<RoomMembersIterator>, ClientError> {
|
||||
Ok(Arc::new(RoomMembersIterator::new(self.inner.members(RoomMemberships::empty()).await?)))
|
||||
}
|
||||
|
||||
pub async fn member(&self, user_id: String) -> Result<Arc<RoomMember>, ClientError> {
|
||||
@@ -1142,3 +1137,27 @@ impl From<AssetType> for RumaAssetType {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(uniffi::Object)]
|
||||
pub struct RoomMembersIterator {
|
||||
chunk_iterator: ChunkIterator<matrix_sdk::room::RoomMember>,
|
||||
}
|
||||
|
||||
impl RoomMembersIterator {
|
||||
fn new(members: Vec<matrix_sdk::room::RoomMember>) -> Self {
|
||||
Self { chunk_iterator: ChunkIterator::new(members) }
|
||||
}
|
||||
}
|
||||
|
||||
#[uniffi::export]
|
||||
impl RoomMembersIterator {
|
||||
fn len(&self) -> u32 {
|
||||
self.chunk_iterator.len()
|
||||
}
|
||||
|
||||
fn next_chunk(&self, chunk_size: u32) -> Option<Vec<Arc<RoomMember>>> {
|
||||
self.chunk_iterator
|
||||
.next(chunk_size)
|
||||
.map(|members| members.into_iter().map(RoomMember::new).map(Arc::new).collect())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user