room: Also show other user avatar if they are alone in room
This commit is contained in:
parent
ae02a70e7b
commit
82bacca9a1
1 changed files with 28 additions and 21 deletions
|
@ -1636,35 +1636,42 @@ impl Room {
|
|||
let avatar_url = matrix_room.avatar_url();
|
||||
let avatar_data = self.avatar_data();
|
||||
|
||||
if avatar_url.is_none() && matrix_room.active_members_count() == 2 {
|
||||
// Fallback to other user's avatar if this is a 1-to-1 room.
|
||||
let members_count = matrix_room.active_members_count();
|
||||
if avatar_url.is_none() && members_count > 0 && members_count <= 2 {
|
||||
// Check if this is a 1-to-1 room to see if we can use a fallback.
|
||||
|
||||
// First, make sure the members are loaded.
|
||||
self.load_members().await;
|
||||
|
||||
let own_user_id = self.session().user().unwrap().user_id();
|
||||
let members = self.members();
|
||||
let mut has_own_member = false;
|
||||
let mut other_member = None;
|
||||
|
||||
if members.n_items() >= 1 {
|
||||
// Try to get the member from the list.
|
||||
// Get the other member from the list.
|
||||
for member in members.iter::<Member>() {
|
||||
match member {
|
||||
Ok(member) => {
|
||||
if member.user_id() != own_user_id
|
||||
&& matches!(
|
||||
member.membership(),
|
||||
Membership::Join | Membership::Invite
|
||||
)
|
||||
{
|
||||
avatar_data.set_image(member.avatar_data().image());
|
||||
return;
|
||||
let Ok(member) = member else {
|
||||
break;
|
||||
};
|
||||
|
||||
if matches!(member.membership(), Membership::Join | Membership::Invite) {
|
||||
if member.user_id() == own_user_id {
|
||||
has_own_member = true;
|
||||
} else {
|
||||
other_member = Some(member);
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
debug!("Error iterating through room members: {error}");
|
||||
|
||||
if has_own_member && other_member.is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to other user's avatar if this is a 1-to-1 room.
|
||||
if members_count == 1 || (members_count == 2 && has_own_member) {
|
||||
if let Some(other_member) = other_member {
|
||||
avatar_data.set_image(other_member.avatar_data().image());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue