From a7c2a645aae08827bdc15f2b49c331a3d037ed18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 21 Apr 2021 15:47:44 +0200 Subject: [PATCH] rooms: Override the joined_members() method so we return the correct RoomMember --- matrix_sdk/src/room/common.rs | 38 ++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/matrix_sdk/src/room/common.rs b/matrix_sdk/src/room/common.rs index de330f29..e29d27ae 100644 --- a/matrix_sdk/src/room/common.rs +++ b/matrix_sdk/src/room/common.rs @@ -182,11 +182,21 @@ impl Common { Ok(()) } - /// Get active members for this room, includes invited, joined members. - pub async fn active_members(&self) -> Result> { + async fn ensure_members(&self) -> Result<()> { if !self.are_members_synced() { 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> { + self.ensure_members().await?; + Ok(self .inner .active_members() @@ -196,11 +206,29 @@ impl Common { .collect()) } + /// Get all the joined members of this room. + /// + /// *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 joined_members(&self) -> Result> { + 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> { - if !self.are_members_synced() { - self.request_members().await?; - } + self.ensure_members().await?; + Ok(self .inner .members()