matrix-sdk: Expose the device methods in the Client.
parent
cdb8b5c1e9
commit
4e99278eac
|
@ -38,7 +38,7 @@ use tracing::{error, info, instrument};
|
||||||
use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore};
|
use matrix_sdk_base::{BaseClient, BaseClientConfig, Room, Session, StateStore};
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
use matrix_sdk_base::Device;
|
use matrix_sdk_base::{CryptoStoreError, Device, UserDevices};
|
||||||
|
|
||||||
use matrix_sdk_common::{
|
use matrix_sdk_common::{
|
||||||
api::r0::{
|
api::r0::{
|
||||||
|
@ -1482,6 +1482,77 @@ impl Client {
|
||||||
homeserver: self.homeserver.clone(),
|
homeserver: self.homeserver.clone(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a specific device of a user.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `user_id` - The unique id of the user that the device belongs to.
|
||||||
|
///
|
||||||
|
/// * `device_id` - The unique id of the device.
|
||||||
|
///
|
||||||
|
/// Returns a `Device` if one is found and the crypto store didn't throw an
|
||||||
|
/// error.
|
||||||
|
///
|
||||||
|
/// This will always return None if the client hasn't been logged in.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use std::convert::TryFrom;
|
||||||
|
/// # use matrix_sdk::{Client, identifiers::UserId};
|
||||||
|
/// # use url::Url;
|
||||||
|
/// # use futures::executor::block_on;
|
||||||
|
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||||
|
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||||
|
/// # let client = Client::new(homeserver).unwrap();
|
||||||
|
/// # block_on(async {
|
||||||
|
/// let device = client.get_device(&alice, "DEVICEID".into()).await;
|
||||||
|
///
|
||||||
|
/// println!("{:?}", device);
|
||||||
|
/// # });
|
||||||
|
/// ```
|
||||||
|
#[cfg(feature = "encryption")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "encryption")))]
|
||||||
|
pub async fn get_device(&self, user_id: &UserId, device_id: &DeviceId) -> Option<Device> {
|
||||||
|
self.base_client.get_device(user_id, device_id).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a map holding all the devices of an user.
|
||||||
|
///
|
||||||
|
/// This will always return an empty map if the client hasn't been logged
|
||||||
|
/// in.
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `user_id` - The unique id of the user that the devices belong to.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # use std::convert::TryFrom;
|
||||||
|
/// # use matrix_sdk::{Client, identifiers::UserId};
|
||||||
|
/// # use url::Url;
|
||||||
|
/// # use futures::executor::block_on;
|
||||||
|
/// # let alice = UserId::try_from("@alice:example.org").unwrap();
|
||||||
|
/// # let homeserver = Url::parse("http://example.com").unwrap();
|
||||||
|
/// # let client = Client::new(homeserver).unwrap();
|
||||||
|
/// # block_on(async {
|
||||||
|
/// let devices = client.get_user_devices(&alice).await.unwrap();
|
||||||
|
///
|
||||||
|
/// for device in devices.devices() {
|
||||||
|
/// println!("{:?}", device);
|
||||||
|
/// }
|
||||||
|
/// # });
|
||||||
|
/// ```
|
||||||
|
#[cfg(feature = "encryption")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "encryption")))]
|
||||||
|
pub async fn get_user_devices(
|
||||||
|
&self,
|
||||||
|
user_id: &UserId,
|
||||||
|
) -> StdResult<UserDevices, CryptoStoreError> {
|
||||||
|
self.base_client.get_user_devices(user_id).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -54,7 +54,7 @@ pub use models::Room;
|
||||||
pub use state::{AllRooms, ClientState};
|
pub use state::{AllRooms, ClientState};
|
||||||
|
|
||||||
#[cfg(feature = "encryption")]
|
#[cfg(feature = "encryption")]
|
||||||
pub use matrix_sdk_crypto::{CryptoStoreError, Device, Sas, TrustState};
|
pub use matrix_sdk_crypto::{CryptoStoreError, Device, Sas, TrustState, UserDevices};
|
||||||
|
|
||||||
#[cfg(feature = "messages")]
|
#[cfg(feature = "messages")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "messages")))]
|
||||||
|
|
Loading…
Reference in New Issue