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
This commit is contained in:
Nicolas Werner 2023-05-09 16:06:15 +02:00
parent 6e67835872
commit 47c54cb397
No known key found for this signature in database
1 changed files with 8 additions and 6 deletions

View File

@ -1133,13 +1133,15 @@ class Room {
/// automatically be set.
Future<void> 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]