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:
Denis Kasak 2020-06-10 14:39:12 +02:00
parent 3e5b6bb460
commit 241d456a81

View file

@ -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::*;