feat(ui): Add Client::get_dm_rooms

This function returns an iterator with all the available rooms that match the behaviour previously in `Client::get_dm`. `Client::get_dm` now just calls this function and returns the first item.
This commit is contained in:
Jorge Martín
2026-04-22 16:38:55 +02:00
committed by Jorge Martin Espinosa
parent 1d7d6c943b
commit 739289cd82
+9 -4
View File
@@ -1791,18 +1791,23 @@ impl Client {
self.create_room(request).await
}
/// Get the existing DM room with the given user, if any.
/// Get the first existing DM room with the given user, if any.
pub fn get_dm_room(&self, user_id: &UserId) -> Option<Room> {
self.get_dm_rooms(user_id).next()
}
/// Get an iterator with the existing DM rooms with the given user.
pub fn get_dm_rooms(&self, user_id: &UserId) -> impl Iterator<Item = Room> {
let rooms = self.joined_rooms();
// Find the room we share with the `user_id` and only with `user_id`
let room = rooms.into_iter().find(|r| {
let rooms = rooms.into_iter().filter(move |r| {
let targets = r.direct_targets();
targets.len() == 1 && targets.contains(<&DirectUserIdentifier>::from(user_id))
});
trace!(?user_id, ?room, "Found DM room with user");
room
trace!(?user_id, ?rooms, "Found DM rooms with user");
rooms
}
/// Search the homeserver's directory for public rooms with a filter.