Add methods for getting and setting display name

master
Amanda Graven 2020-12-07 11:17:26 +01:00
parent 804bd221b2
commit a26dc3179a
No known key found for this signature in database
GPG Key ID: 45C461CDC9286390
1 changed files with 17 additions and 0 deletions

View File

@ -74,6 +74,7 @@ use matrix_sdk_common::{
join_room_by_id, join_room_by_id_or_alias, kick_user, leave_room, Invite3pid, join_room_by_id, join_room_by_id_or_alias, kick_user, leave_room, Invite3pid,
}, },
message::{get_message_events, send_message_event}, message::{get_message_events, send_message_event},
profile::{get_display_name, set_display_name},
read_marker::set_read_marker, read_marker::set_read_marker,
receipt::create_receipt, receipt::create_receipt,
room::create_room, room::create_room,
@ -429,6 +430,22 @@ impl Client {
session.as_ref().cloned().map(|s| s.user_id) session.as_ref().cloned().map(|s| s.user_id)
} }
/// Fetches the display name of the owner of the client.
pub async fn user_display_name(&self) -> Result<Option<String>> {
let user_id = self.user_id().await.ok_or(Error::AuthenticationRequired)?;
let request = get_display_name::Request::new(&user_id);
let response = self.send(request).await?;
Ok(response.displayname)
}
/// Sets the display name of the owner of the client.
pub async fn set_user_display_name(&self, name: Option<&str>) -> Result<()> {
let user_id = self.user_id().await.ok_or(Error::AuthenticationRequired)?;
let request = set_display_name::Request::new(&user_id, name);
self.send(request).await?;
Ok(())
}
/// Add `EventEmitter` to `Client`. /// Add `EventEmitter` to `Client`.
/// ///
/// The methods of `EventEmitter` are called when the respective `RoomEvents` occur. /// The methods of `EventEmitter` are called when the respective `RoomEvents` occur.