Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,13 @@ class Client extends MatrixApi {
return null;
}

Map<String, dynamic> get directChats =>
_accountData['m.direct']?.content ?? {};
Map<String, List<String>> get directChats =>
(_accountData['m.direct']?.content ?? {}).map(
(userId, list) => MapEntry(
userId,
(list is! List) ? [] : list.whereType<String>().toList(),
),
);

/// Returns the (first) room ID from the store which is a private chat with the user [userId].
/// Returns null if there is none.
Expand Down
22 changes: 11 additions & 11 deletions lib/src/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class Room {
final cache = _cachedDirectChatMatrixId;
if (cache != null) {
final roomIds = client.directChats[cache];
if (roomIds is List && roomIds.contains(id)) {
if (roomIds != null && roomIds.contains(id)) {
return cache;
}
}
Expand Down Expand Up @@ -1381,21 +1381,21 @@ class Room {

/// Sets this room as a direct chat for this user if not already.
Future<void> addToDirectChat(String userID) async {
final directChats = client.directChats;
if (directChats[userID] is List) {
if (!directChats[userID].contains(id)) {
directChats[userID].add(id);
} else {
return;
} // Is already in direct chats
} else {
directChats[userID] = [id];
final dmRooms = List<String>.from(client.directChats[userID] ?? []);
if (dmRooms.contains(id)) {
Logs().d('Already a direct chat.');
return;
}

dmRooms.add(id);

await client.setAccountData(
client.userID!,
'm.direct',
directChats,
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the 'markasdm' in commands_test.dart needs to be changed to account for this

...client.directChats,
userID: dmRooms,
},
);
return;
}
Expand Down
Loading