rooms: Override the joined_members() method so we return the correct RoomMember

master
Damir Jelić 2021-04-21 15:47:44 +02:00
parent 2a5ede9e1a
commit a7c2a645aa
1 changed files with 33 additions and 5 deletions

View File

@ -182,11 +182,21 @@ impl Common {
Ok(()) Ok(())
} }
/// Get active members for this room, includes invited, joined members. async fn ensure_members(&self) -> Result<()> {
pub async fn active_members(&self) -> Result<Vec<RoomMember>> {
if !self.are_members_synced() { if !self.are_members_synced() {
self.request_members().await?; self.request_members().await?;
} }
Ok(())
}
/// Get active members for this room, includes invited, joined members.
///
/// *Note*: This method will fetch the members from the homeserver if the
/// member list isn't synchronized due to member lazy loading.
pub async fn active_members(&self) -> Result<Vec<RoomMember>> {
self.ensure_members().await?;
Ok(self Ok(self
.inner .inner
.active_members() .active_members()
@ -196,11 +206,29 @@ impl Common {
.collect()) .collect())
} }
/// Get all members for this room, includes invited, joined and left members. /// Get all the joined members of this room.
pub async fn members(&self) -> Result<Vec<RoomMember>> { ///
if !self.are_members_synced() { /// *Note*: This method will fetch the members from the homeserver if the
self.request_members().await?; /// member list isn't synchronized due to member lazy loading.
pub async fn joined_members(&self) -> Result<Vec<RoomMember>> {
self.ensure_members().await?;
Ok(self
.inner
.members()
.await?
.into_iter()
.map(|member| RoomMember::new(self.client.clone(), member))
.collect())
} }
/// Get all members for this room, includes invited, joined and left members.
///
/// *Note*: This method will fetch the members from the homeserver if the
/// member list isn't synchronized due to member lazy loading.
pub async fn members(&self) -> Result<Vec<RoomMember>> {
self.ensure_members().await?;
Ok(self Ok(self
.inner .inner
.members() .members()