Skip to content

Render reason for invite rejection. #29257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/TextForEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions test/unit-tests/TextForEvent-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,49 @@ 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(
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()", () => {
Expand Down
Loading