♻️ Render Room avatar using the RoomMember ones, if not set

This commit is contained in:
2024-05-22 16:42:20 +02:00
parent 35e191eb62
commit 19d64d7ac5
7 changed files with 126 additions and 109 deletions

View File

@@ -4,7 +4,7 @@ use std::{
rc::Rc,
};
use matrix_sdk::{room::RoomMember as MatrixRoomMember, ruma::OwnedRoomId};
use matrix_sdk::ruma::OwnedMxcUri;
use tracing::error;
use super::{
@@ -13,9 +13,14 @@ use super::{
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,
@@ -26,14 +31,18 @@ pub struct RoomMember {
}
impl RoomMember {
fn new(
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),
@@ -41,24 +50,14 @@ impl RoomMember {
}
}
// TODO: Use a factory instead...
pub async fn from_matrix(
matrix_room_member: &MatrixRoomMember,
room_id: &OwnedRoomId,
messaging_provider: Rc<dyn MemberMessagingProviderInterface>,
) -> Self {
Self::new(
UserId::from(matrix_room_member.user_id()),
room_id.clone(),
matrix_room_member.is_account_user(),
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
@@ -71,7 +70,11 @@ impl RoomMember {
pub async fn get_avatar(&self) -> Option<Avatar> {
match self
.messaging_provider
.get_avatar(&self.room_id, &self.id)
.get_avatar(
self.avatar_url.clone(),
self.room_id.clone(),
self.id.clone(),
)
.await
{
Ok(avatar) => avatar,