feat(sdk): Add a method to check if a room contains only verified devices

master
Damir Jelić 2021-08-13 14:03:21 +02:00
parent 0e9a1b42ec
commit 1bcc74738e
1 changed files with 21 additions and 0 deletions

View File

@ -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<bool> {
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)
}
}