Merge branch 'nico/fix-dm-joins' into 'main'

fix: mark DMs as DMs properly when joining

Closes famedly/company/product-management#1006

See merge request famedly/company/frontend/famedlysdk!1291
This commit is contained in:
td 2023-05-09 14:54:43 +00:00
commit 89fbd41b4b
1 changed files with 8 additions and 6 deletions

View File

@ -1133,13 +1133,15 @@ class Room {
/// automatically be set. /// automatically be set.
Future<void> join({bool leaveIfNotFound = true}) async { Future<void> join({bool leaveIfNotFound = true}) async {
try { try {
await client.joinRoomById(id); // If this is a DM, mark it as a DM first, because otherwise the current member
final invitation = getState(EventTypes.RoomMember, client.userID!); // event might be the join event already and there is also a race condition there for SDK users.
if (invitation != null && final dmId = directChatMatrixID;
invitation.content['is_direct'] is bool && if (dmId != null) {
invitation.content['is_direct']) { await addToDirectChat(dmId);
await addToDirectChat(invitation.senderId);
} }
// now join
await client.joinRoomById(id);
} on MatrixException catch (exception) { } on MatrixException catch (exception) {
if (leaveIfNotFound && if (leaveIfNotFound &&
[MatrixError.M_NOT_FOUND, MatrixError.M_UNKNOWN] [MatrixError.M_NOT_FOUND, MatrixError.M_UNKNOWN]