dm-user-list: Load room members from SDK
Do not expect that the members list of a room is always available.
This commit is contained in:
parent
6ebb231995
commit
2d6aaadbd6
1 changed files with 28 additions and 26 deletions
|
@ -1,11 +1,14 @@
|
||||||
use gtk::{gio, glib, glib::clone, prelude::*, subclass::prelude::*};
|
use gtk::{gio, glib, glib::clone, prelude::*, subclass::prelude::*};
|
||||||
use matrix_sdk::ruma::{api::client::user_directory::search_users, OwnedUserId, UserId};
|
use matrix_sdk::{
|
||||||
use tracing::{debug, error};
|
ruma::{api::client::user_directory::search_users, OwnedUserId, UserId},
|
||||||
|
RoomMemberships,
|
||||||
|
};
|
||||||
|
use tracing::error;
|
||||||
|
|
||||||
use super::DmUser;
|
use super::DmUser;
|
||||||
use crate::{
|
use crate::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
session::model::{Member, Room, Session},
|
session::model::{Room, Session},
|
||||||
spawn, spawn_tokio,
|
spawn, spawn_tokio,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -229,35 +232,34 @@ impl DmUserList {
|
||||||
let Some(room) = room.upgrade() else {
|
let Some(room) = room.upgrade() else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let members = room.members();
|
let matrix_room = room.matrix_room();
|
||||||
|
|
||||||
if !room.is_joined() || room.matrix_room().active_members_count() > 2 {
|
if !room.is_joined() || matrix_room.active_members_count() > 2 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we have all members loaded, in most cases members should
|
let handle = spawn_tokio!(async move {
|
||||||
// already be loaded
|
matrix_room.members(RoomMemberships::ACTIVE).await
|
||||||
room.members().load().await;
|
});
|
||||||
|
|
||||||
if members.n_items() >= 1 {
|
let members = match handle.await.unwrap() {
|
||||||
|
Ok(members) => members,
|
||||||
|
Err(error) => {
|
||||||
|
error!("Failed to load members: {error}");
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if !members.is_empty() {
|
||||||
let mut found_others = false;
|
let mut found_others = false;
|
||||||
for member in members.iter::<Member>() {
|
for member in &members {
|
||||||
match member {
|
if member.user_id() != own_user_id
|
||||||
Ok(member) => {
|
&& member.user_id() != other_user_id
|
||||||
if member.user_id() != own_user_id
|
{
|
||||||
&& &member.user_id() != other_user_id
|
// We found other members in this room, let's ignore
|
||||||
{
|
// the room.
|
||||||
// We found other members in this room, let's ignore
|
found_others = true;
|
||||||
// the
|
break;
|
||||||
// room
|
|
||||||
found_others = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(error) => {
|
|
||||||
debug!("Error iterating through room members: {error}");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue