From 77561ced0749c0db7c243990a597a520518cdd26 Mon Sep 17 00:00:00 2001 From: Patrick Hettich Date: Fri, 16 Feb 2024 11:47:26 +0100 Subject: [PATCH] fix: Use name of other participant on archived rooms --- lib/src/room.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/src/room.dart b/lib/src/room.dart index c4fffd7c..f1ec54c4 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -290,6 +290,19 @@ class Room { .calcDisplayname(i18n: i18n); if (sender != null) return sender; } + if (isArchived) { + // In case of a direct chat, we need to get the room-members via the RoomMember event-type + // then we have to make sure to get the other room-member that is not us, to add them to the display name. + final roomMemberEvents = states.entries + .firstWhereOrNull((element) => element.key == EventTypes.RoomMember); + final otherRoomMember = roomMemberEvents?.value.entries + .firstWhereOrNull((entry) => entry.value.senderId != client.userID); + + if (otherRoomMember?.value.prevContent?.tryGet('displayname') != null) { + return i18n.wasDirectChatDisplayName( + otherRoomMember!.value.prevContent!.tryGet('displayname')!); + } + } if (membership == Membership.leave) { final invitation = getState(EventTypes.RoomMember, client.userID!); if (invitation != null &&