94 lines
2.0 KiB
Rust
94 lines
2.0 KiB
Rust
use std::{
|
|
cell::RefCell,
|
|
fmt::{Debug, Formatter},
|
|
rc::Rc,
|
|
};
|
|
|
|
use matrix_sdk::ruma::OwnedMxcUri;
|
|
use tracing::error;
|
|
|
|
use super::{
|
|
common::{Avatar, UserId},
|
|
messaging_interface::MemberMessagingProviderInterface,
|
|
room::RoomId,
|
|
};
|
|
|
|
pub type AvatarUrl = OwnedMxcUri;
|
|
|
|
#[derive(Clone)]
|
|
pub struct RoomMember {
|
|
id: UserId,
|
|
|
|
display_name: Option<String>,
|
|
avatar_url: Option<AvatarUrl>,
|
|
room_id: RoomId,
|
|
is_account_user: bool,
|
|
|
|
#[allow(dead_code)]
|
|
avatar: RefCell<Option<Avatar>>,
|
|
|
|
messaging_provider: Rc<dyn MemberMessagingProviderInterface>,
|
|
}
|
|
|
|
impl RoomMember {
|
|
pub fn new(
|
|
id: UserId,
|
|
display_name: Option<String>,
|
|
avatar_url: Option<AvatarUrl>,
|
|
room_id: RoomId,
|
|
is_account_user: bool,
|
|
messaging_provider: Rc<dyn MemberMessagingProviderInterface>,
|
|
) -> Self {
|
|
Self {
|
|
id,
|
|
display_name,
|
|
avatar_url,
|
|
room_id,
|
|
is_account_user,
|
|
avatar: RefCell::new(None),
|
|
messaging_provider,
|
|
}
|
|
}
|
|
|
|
pub fn id(&self) -> &UserId {
|
|
&self.id
|
|
}
|
|
|
|
pub fn display_name(&self) -> &Option<String> {
|
|
&self.display_name
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub fn room_id(&self) -> &RoomId {
|
|
&self.room_id
|
|
}
|
|
|
|
pub fn is_account_user(&self) -> bool {
|
|
self.is_account_user
|
|
}
|
|
|
|
pub async fn get_avatar(&self) -> Option<Avatar> {
|
|
match self
|
|
.messaging_provider
|
|
.get_avatar(
|
|
self.avatar_url.clone(),
|
|
self.room_id.clone(),
|
|
self.id.clone(),
|
|
)
|
|
.await
|
|
{
|
|
Ok(avatar) => avatar,
|
|
Err(err) => {
|
|
error!("err={}", err);
|
|
None
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Debug for RoomMember {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
|
|
f.debug_struct("RoomMember").field("id", &self.id).finish()
|
|
}
|
|
}
|