From 47c54cb39740c570a7005a3bc4587dff51b4c20a Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 9 May 2023 16:06:15 +0200 Subject: [PATCH] fix: mark DMs as DMs properly when joining If we join first, it is possible that our member event is not the invite event anymore. As such we should fetch that state first, before joining. But also there is little reason not to mark the room as a DM immediately. That prevents the room from temporarily becoming a group room, that might be visible in the UI temporarily. fixes https://gitlab.com/famedly/company/product-management/-/issues/1006 --- lib/src/room.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 053aa15f..44a5e425 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -1133,13 +1133,15 @@ class Room { /// automatically be set. Future join({bool leaveIfNotFound = true}) async { try { - await client.joinRoomById(id); - final invitation = getState(EventTypes.RoomMember, client.userID!); - if (invitation != null && - invitation.content['is_direct'] is bool && - invitation.content['is_direct']) { - await addToDirectChat(invitation.senderId); + // If this is a DM, mark it as a DM first, because otherwise the current member + // event might be the join event already and there is also a race condition there for SDK users. + final dmId = directChatMatrixID; + if (dmId != null) { + await addToDirectChat(dmId); } + + // now join + await client.joinRoomById(id); } on MatrixException catch (exception) { if (leaveIfNotFound && [MatrixError.M_NOT_FOUND, MatrixError.M_UNKNOWN]