From d3e64c114f73866a7d37f20c69e146049d3d6b24 Mon Sep 17 00:00:00 2001 From: Doug <6060466+pixlwave@users.noreply.github.com> Date: Fri, 4 Aug 2023 12:22:14 +0100 Subject: [PATCH] Fix a crash when opening v11 rooms. (#7635) https://github.com/matrix-org/matrix-spec-proposals/pull/2175 --- .../Utils/EventFormatter/MXKEventFormatter.m | 46 ++++++++++--------- changelog.d/7633.bugfix | 1 + 2 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 changelog.d/7633.bugfix diff --git a/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m b/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m index 19fae141d2..7ae98184a3 100644 --- a/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m +++ b/Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m @@ -833,35 +833,39 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent*)event NSString *creatorId; MXJSONModelSetString(creatorId, event.content[@"creator"]); - if (creatorId) + if (!creatorId) { - if ([creatorId isEqualToString:mxSession.myUserId]) + // Room version 11 removes `creator` in favour of `sender`. + // https://github.com/matrix-org/matrix-spec-proposals/pull/2175 + creatorId = event.sender; + } + + if ([creatorId isEqualToString:mxSession.myUserId]) + { + if (isRoomDirect) { - if (isRoomDirect) - { - displayText = [VectorL10n noticeRoomCreatedByYouForDm]; - } - else - { - displayText = [VectorL10n noticeRoomCreatedByYou]; - } + displayText = [VectorL10n noticeRoomCreatedByYouForDm]; } else { - if (isRoomDirect) - { - displayText = [VectorL10n noticeRoomCreatedForDm:(roomState ? [roomState.members memberName:creatorId] : creatorId)]; - } - else - { - displayText = [VectorL10n noticeRoomCreated:(roomState ? [roomState.members memberName:creatorId] : creatorId)]; - } + displayText = [VectorL10n noticeRoomCreatedByYou]; } - // Append redacted info if any - if (redactedInfo) + } + else + { + if (isRoomDirect) { - displayText = [NSString stringWithFormat:@"%@ %@", displayText, redactedInfo]; + displayText = [VectorL10n noticeRoomCreatedForDm:(roomState ? [roomState.members memberName:creatorId] : creatorId)]; } + else + { + displayText = [VectorL10n noticeRoomCreated:(roomState ? [roomState.members memberName:creatorId] : creatorId)]; + } + } + // Append redacted info if any + if (redactedInfo) + { + displayText = [NSString stringWithFormat:@"%@ %@", displayText, redactedInfo]; } break; } diff --git a/changelog.d/7633.bugfix b/changelog.d/7633.bugfix new file mode 100644 index 0000000000..b7345971eb --- /dev/null +++ b/changelog.d/7633.bugfix @@ -0,0 +1 @@ +Fix a crash when opening v11 rooms. \ No newline at end of file