Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Hide pinned message link in timeline when the last pinned message is …
Browse files Browse the repository at this point in the history
…unpinned
  • Loading branch information
florianduros committed Sep 6, 2024
1 parent 33c9c04 commit 64967bf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
32 changes: 31 additions & 1 deletion src/TextForEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,37 @@ function textForPinnedEvent(event: MatrixEvent, client: MatrixClient, allowJSX:
}

if (newlyUnpinned.length === 1 && newlyPinned.length === 0) {
const emptyPinned = pinned.length === 0;

// A single message was unpinned, include a link to that message.
if (allowJSX) {
const messageId = newlyUnpinned.pop()!;

// If there are no remaining pinned messages, don't show the link to all the pinned messages
if (emptyPinned) {
return () => (
<span>
{_t(
"timeline|m.room.pinned_events|unpinned_last_link",
{ senderName },
{
a: (sub) => (
<AccessibleButton
kind="link_inline"
onClick={() => {
PosthogTrackers.trackInteraction("PinnedMessageStateEventClick");
highlightEvent(roomId, messageId);
}}
>
{sub}
</AccessibleButton>
),
},
)}
</span>
);
}

return () => (
<span>
{_t(
Expand Down Expand Up @@ -647,7 +674,10 @@ function textForPinnedEvent(event: MatrixEvent, client: MatrixClient, allowJSX:
);
}

return () => _t("timeline|m.room.pinned_events|unpinned", { senderName });
return () =>
emptyPinned
? _t("timeline|m.room.pinned_events|unpinned_last", { senderName })
: _t("timeline|m.room.pinned_events|unpinned", { senderName });
}

if (allowJSX) {
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -3479,6 +3479,8 @@
"pinned": "%(senderName)s pinned a message to this room. See all pinned messages.",
"pinned_link": "%(senderName)s pinned <a>a message</a> to this room. See all <b>pinned messages</b>.",
"unpinned": "%(senderName)s unpinned a message from this room. See all pinned messages.",
"unpinned_last": "%(senderName)s unpinned a message from this room.",
"unpinned_last_link": "%(senderName)s unpinned <a>a message</a> from this room.",
"unpinned_link": "%(senderName)s unpinned <a>a message</a> from this room. See all <b>pinned messages</b>."
},
"m.room.power_levels": {
Expand Down
2 changes: 1 addition & 1 deletion test/TextForEvent-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe("TextForEvent", () => {
const plainText = textForEvent(event, mockClient);
const component = render(textForEvent(event, mockClient, true) as ReactElement);

const expectedText = "@foo:example.com unpinned a message from this room. See all pinned messages.";
const expectedText = "@foo:example.com unpinned a message from this room.";
expect(plainText).toBe(expectedText);
expect(component.container).toHaveTextContent(expectedText);
});
Expand Down

0 comments on commit 64967bf

Please sign in to comment.