From 8d063965511e644dfa2bedd744e0339c76637322 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 13 Feb 2025 10:27:05 +0000 Subject: [PATCH 1/3] Render reason for invite rejection. --- src/TextForEvent.tsx | 5 ++++- src/i18n/strings/en_EN.json | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index bdb7e8cbe0e..85b0d216be1 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -190,7 +190,10 @@ function textForMemberEvent( case KnownMembership.Leave: if (ev.getSender() === ev.getStateKey()) { if (prevContent.membership === KnownMembership.Invite) { - return () => _t("timeline|m.room.member|reject_invite", { targetName }); + return () => + reason + ? _t("timeline|m.room.member|reject_invite_reason", { targetName, reason }) + : _t("timeline|m.room.member|reject_invite", { targetName }); } else { return () => reason diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index a9825a16e4d..982d72c05ec 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -3455,6 +3455,7 @@ "left_reason": "%(targetName)s left the room: %(reason)s", "no_change": "%(senderName)s made no change", "reject_invite": "%(targetName)s rejected the invitation", + "reject_invite_reason": "%(targetName)s rejected the invitation: %(reason)s", "remove_avatar": "%(senderName)s removed their profile picture", "remove_name": "%(senderName)s removed their display name (%(oldDisplayName)s)", "set_avatar": "%(senderName)s set a profile picture", From 2baf74a1fda992a589de584c208b3116866e5a80 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 13 Feb 2025 10:39:01 +0000 Subject: [PATCH 2/3] Add test --- test/unit-tests/TextForEvent-test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/unit-tests/TextForEvent-test.ts b/test/unit-tests/TextForEvent-test.ts index 4dfccbb93e9..91f6598bd0a 100644 --- a/test/unit-tests/TextForEvent-test.ts +++ b/test/unit-tests/TextForEvent-test.ts @@ -518,6 +518,28 @@ describe("TextForEvent", () => { ), ).toMatchInlineSnapshot(`"Andy changed their display name and profile picture"`); }); + + it("should handle rejected invites with a reason", () => { + expect( + textForEvent( + new MatrixEvent({ + type: "m.room.member", + sender: "@a:foo", + content: { + membership: KnownMembership.Leave, + reason: "I don't want to be in this room.", + }, + unsigned: { + prev_content: { + membership: KnownMembership.Invite, + }, + }, + state_key: "@a:foo", + }), + mockClient, + ), + ).toMatchInlineSnapshot(`"Member rejected the invitation: I don't want to be in this room."`); + }); }); describe("textForJoinRulesEvent()", () => { From cd812164efe233d0d684765daeccb732a836cbbe Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 13 Feb 2025 10:51:17 +0000 Subject: [PATCH 3/3] extra test --- test/unit-tests/TextForEvent-test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/unit-tests/TextForEvent-test.ts b/test/unit-tests/TextForEvent-test.ts index 91f6598bd0a..a7c1ef3b9e7 100644 --- a/test/unit-tests/TextForEvent-test.ts +++ b/test/unit-tests/TextForEvent-test.ts @@ -519,6 +519,27 @@ describe("TextForEvent", () => { ).toMatchInlineSnapshot(`"Andy changed their display name and profile picture"`); }); + it("should handle rejected invites", () => { + expect( + textForEvent( + new MatrixEvent({ + type: "m.room.member", + sender: "@a:foo", + content: { + membership: KnownMembership.Leave, + }, + unsigned: { + prev_content: { + membership: KnownMembership.Invite, + }, + }, + state_key: "@a:foo", + }), + mockClient, + ), + ).toMatchInlineSnapshot(`"Member rejected the invitation"`); + }); + it("should handle rejected invites with a reason", () => { expect( textForEvent(