fix: Pick right DM room, if multiple are set

This commit is contained in:
Sorunome 2020-11-08 15:09:12 +01:00
parent 588d7eb1a6
commit b0043ea0e4
No known key found for this signature in database
GPG Key ID: B19471D07FC9BE9C
1 changed files with 14 additions and 1 deletions

View File

@ -199,12 +199,25 @@ class Client extends MatrixApi {
if (accountData['m.direct'] != null &&
accountData['m.direct'].content[userId] is List<dynamic> &&
accountData['m.direct'].content[userId].length > 0) {
final potentialRooms = <Room>{};
for (final roomId in accountData['m.direct'].content[userId]) {
final room = getRoomById(roomId);
if (room != null && room.membership == Membership.join) {
return roomId;
potentialRooms.add(room);
}
}
if (potentialRooms.isNotEmpty) {
return potentialRooms
.fold(
null,
(prev, r) => prev == null
? r
: (prev.lastEvent.originServerTs <
r.lastEvent.originServerTs
? r
: prev))
.id;
}
}
for (var i = 0; i < rooms.length; i++) {
if (rooms[i].membership == Membership.invite &&