From 1bcc74738ea93e41670916d762af71dbc85639ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Fri, 13 Aug 2021 14:03:21 +0200 Subject: [PATCH] feat(sdk): Add a method to check if a room contains only verified devices --- matrix_sdk/src/room/common.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/matrix_sdk/src/room/common.rs b/matrix_sdk/src/room/common.rs index fc7cc8a11..859e2ae24 100644 --- a/matrix_sdk/src/room/common.rs +++ b/matrix_sdk/src/room/common.rs @@ -376,4 +376,25 @@ impl Common { .await .map_err(Into::into) } + + /// Check if all members of this room are verified and all their devices are + /// verified. + /// + /// Returns true if all devices in the room are verified, otherwise false. + #[cfg(feature = "encryption")] + #[cfg_attr(feature = "docs", doc(cfg(encryption)))] + pub async fn contains_only_verified_devices(&self) -> Result { + let user_ids = self.client.store().get_user_ids(self.room_id()).await?; + + for user_id in user_ids { + let devices = self.client.get_user_devices(&user_id).await?; + let any_unverified = devices.devices().any(|d| !d.verified()); + + if any_unverified { + return Ok(false); + } + } + + Ok(true) + } }