Add RoomMember::name.
Returns the most ergonomic name for the member (either the display name (if set) or the MXID).
This commit is contained in:
parent
3e5b6bb460
commit
241d456a81
1 changed files with 10 additions and 1 deletions
|
@ -32,7 +32,7 @@ use serde::{Deserialize, Serialize};
|
|||
/// A Matrix room member.
|
||||
///
|
||||
pub struct RoomMember {
|
||||
/// The unique mxid of the user.
|
||||
/// The unique MXID of the user.
|
||||
pub user_id: UserId,
|
||||
/// The human readable name of the user.
|
||||
pub display_name: Option<String>,
|
||||
|
@ -100,6 +100,15 @@ impl RoomMember {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the most ergonomic name available for the member.
|
||||
///
|
||||
/// This is the member's display name if it is set, otherwise their MXID.
|
||||
pub fn name(&self) -> String {
|
||||
self.display_name
|
||||
.clone()
|
||||
.unwrap_or_else(|| format!("{}", self.user_id))
|
||||
}
|
||||
|
||||
pub fn update_member(&mut self, event: &MemberEvent) -> bool {
|
||||
use MembershipChange::*;
|
||||
|
||||
|
|
Loading…
Reference in a new issue