diff --git a/lib/src/Client.dart b/lib/src/Client.dart index 90561afc..84ee5094 100644 --- a/lib/src/Client.dart +++ b/lib/src/Client.dart @@ -123,12 +123,14 @@ class Client { /// Returns the (first) room ID from the store which is a private chat with the user [userId]. /// Returns null if there is none. - String getDirectChatFromUserId(String userId) => - accountData["m.direct"] != null && - accountData["m.direct"].content[userId] is List && - accountData["m.direct"].content[userId].length > 0 - ? accountData["m.direct"].content[userId][0] - : null; + String getDirectChatFromUserId(String userId) => accountData["m.direct"] != + null && + accountData["m.direct"].content[userId] is List && + accountData["m.direct"].content[userId].length > 0 && + roomList.getRoomById(accountData["m.direct"].content[userId][0]) != + null + ? accountData["m.direct"].content[userId][0] + : null; /// Checks the supported versions of the Matrix protocol and the supported /// login types. Returns false if the server is not compatible with the diff --git a/lib/src/RoomList.dart b/lib/src/RoomList.dart index aa9bbfa7..9d976071 100644 --- a/lib/src/RoomList.dart +++ b/lib/src/RoomList.dart @@ -78,6 +78,13 @@ class RoomList { return null; } + Room getRoomById(String id) { + for (int j = 0; j < rooms.length; j++) { + if (rooms[j].id == id) return rooms[j]; + } + return null; + } + void _handleRoomUpdate(RoomUpdate chatUpdate) { // Update the chat list item. // Search the room in the rooms