From 2999ceec9e3644c815f1df38ff3872d4eac744dd Mon Sep 17 00:00:00 2001 From: Sorunome Date: Mon, 22 Jun 2020 06:48:30 +0000 Subject: [PATCH] potentially fix direct chats going missing --- lib/src/client.dart | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index ef6b2a4..bcfc3ff 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -168,13 +168,12 @@ class Client { if (accountData['m.direct'] != null && accountData['m.direct'].content[userId] is List && accountData['m.direct'].content[userId].length > 0) { - if (getRoomById(accountData['m.direct'].content[userId][0]) != null) { - return accountData['m.direct'].content[userId][0]; + for (final roomId in accountData['m.direct'].content[userId]) { + final room = getRoomById(roomId); + if (room != null && room.membership == Membership.join) { + return roomId; + } } - (accountData['m.direct'].content[userId] as List) - .remove(accountData['m.direct'].content[userId][0]); - api.setAccountData(userId, 'm.direct', directChats); - return getDirectChatFromUserId(userId); } for (var i = 0; i < rooms.length; i++) { if (rooms[i].membership == Membership.invite &&