From 36ca7846908eff458da18654a2c92c89e527d7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 12 Aug 2020 17:16:27 +0200 Subject: [PATCH] crypto: Expose a method to get all devices of an user. --- matrix_sdk_crypto/src/machine.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/matrix_sdk_crypto/src/machine.rs b/matrix_sdk_crypto/src/machine.rs index 9c13bd24..62747604 100644 --- a/matrix_sdk_crypto/src/machine.rs +++ b/matrix_sdk_crypto/src/machine.rs @@ -58,7 +58,7 @@ use super::{ }, store::{memorystore::MemoryStore, Result as StoreResult}, verification::{Sas, VerificationMachine}, - CryptoStore, + CryptoStore, UserDevices, }; /// A map from the algorithm and device id to a one-time key. @@ -1327,6 +1327,33 @@ impl OlmMachine { .ok() .flatten() } + + /// Get a map holding all the devices of an user. + /// + /// # Arguments + /// + /// * `user_id` - The unique id of the user that the devices belong to. + /// + /// # Example + /// + /// ``` + /// # use std::convert::TryFrom; + /// # use matrix_sdk_crypto::OlmMachine; + /// # use matrix_sdk_common::identifiers::UserId; + /// # use futures::executor::block_on; + /// # let alice = UserId::try_from("@alice:example.org").unwrap(); + /// # let machine = OlmMachine::new(&alice, "DEVICEID".into()); + /// # block_on(async { + /// let devices = machine.get_user_devices(&alice).await.unwrap(); + /// + /// for device in devices.devices() { + /// println!("{:?}", device); + /// } + /// # }); + /// ``` + pub async fn get_user_devices(&self, user_id: &UserId) -> StoreResult { + self.store.get_user_devices(user_id).await + } } #[cfg(test)]