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

Commit 64967bf

Browse files
committed
Hide pinned message link in timeline when the last pinned message is unpinned
1 parent 33c9c04 commit 64967bf

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/TextForEvent.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,37 @@ function textForPinnedEvent(event: MatrixEvent, client: MatrixClient, allowJSX:
615615
}
616616

617617
if (newlyUnpinned.length === 1 && newlyPinned.length === 0) {
618+
const emptyPinned = pinned.length === 0;
619+
618620
// A single message was unpinned, include a link to that message.
619621
if (allowJSX) {
620622
const messageId = newlyUnpinned.pop()!;
621623

624+
// If there are no remaining pinned messages, don't show the link to all the pinned messages
625+
if (emptyPinned) {
626+
return () => (
627+
<span>
628+
{_t(
629+
"timeline|m.room.pinned_events|unpinned_last_link",
630+
{ senderName },
631+
{
632+
a: (sub) => (
633+
<AccessibleButton
634+
kind="link_inline"
635+
onClick={() => {
636+
PosthogTrackers.trackInteraction("PinnedMessageStateEventClick");
637+
highlightEvent(roomId, messageId);
638+
}}
639+
>
640+
{sub}
641+
</AccessibleButton>
642+
),
643+
},
644+
)}
645+
</span>
646+
);
647+
}
648+
622649
return () => (
623650
<span>
624651
{_t(
@@ -647,7 +674,10 @@ function textForPinnedEvent(event: MatrixEvent, client: MatrixClient, allowJSX:
647674
);
648675
}
649676

650-
return () => _t("timeline|m.room.pinned_events|unpinned", { senderName });
677+
return () =>
678+
emptyPinned
679+
? _t("timeline|m.room.pinned_events|unpinned_last", { senderName })
680+
: _t("timeline|m.room.pinned_events|unpinned", { senderName });
651681
}
652682

653683
if (allowJSX) {

src/i18n/strings/en_EN.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3479,6 +3479,8 @@
34793479
"pinned": "%(senderName)s pinned a message to this room. See all pinned messages.",
34803480
"pinned_link": "%(senderName)s pinned <a>a message</a> to this room. See all <b>pinned messages</b>.",
34813481
"unpinned": "%(senderName)s unpinned a message from this room. See all pinned messages.",
3482+
"unpinned_last": "%(senderName)s unpinned a message from this room.",
3483+
"unpinned_last_link": "%(senderName)s unpinned <a>a message</a> from this room.",
34823484
"unpinned_link": "%(senderName)s unpinned <a>a message</a> from this room. See all <b>pinned messages</b>."
34833485
},
34843486
"m.room.power_levels": {

test/TextForEvent-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe("TextForEvent", () => {
103103
const plainText = textForEvent(event, mockClient);
104104
const component = render(textForEvent(event, mockClient, true) as ReactElement);
105105

106-
const expectedText = "@foo:example.com unpinned a message from this room. See all pinned messages.";
106+
const expectedText = "@foo:example.com unpinned a message from this room.";
107107
expect(plainText).toBe(expectedText);
108108
expect(component.container).toHaveTextContent(expectedText);
109109
});

0 commit comments

Comments
 (0)