From aaeb9969a47db6abdf7200668ea35d4f68c1d52e Mon Sep 17 00:00:00 2001 From: Paulo Pinto Date: Wed, 11 Aug 2021 14:56:59 +0100 Subject: [PATCH] Handle case where one message is pinned, and another unpinned Signed-off-by: Paulo Pinto --- src/TextForEvent.tsx | 4 ++-- test/TextForEvent-test.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/TextForEvent.tsx b/src/TextForEvent.tsx index a85d44ecb3..1c5e9ec6f0 100644 --- a/src/TextForEvent.tsx +++ b/src/TextForEvent.tsx @@ -435,7 +435,7 @@ function textForPinnedEvent(event: MatrixEvent, allowJSX: boolean): () => string const newlyPinned = pinned.filter(item => previouslyPinned.indexOf(item) < 0); const newlyUnpinned = previouslyPinned.filter(item => pinned.indexOf(item) < 0); - if (newlyPinned.length === 1) { + if (newlyPinned.length === 1 && newlyUnpinned.length === 0) { // A single message was pinned, include a link to that message. if (allowJSX) { const messageId = newlyPinned.pop(); @@ -463,7 +463,7 @@ function textForPinnedEvent(event: MatrixEvent, allowJSX: boolean): () => string return () => _t("%(senderName)s pinned a message to this room. See all pinned messages.", { senderName }); } - if (newlyUnpinned.length === 1) { + if (newlyUnpinned.length === 1 && newlyPinned.length === 0) { // A single message was unpinned, include a link to that message. if (allowJSX) { const messageId = newlyUnpinned.pop(); diff --git a/test/TextForEvent-test.ts b/test/TextForEvent-test.ts index 285d4de232..b8a459af67 100644 --- a/test/TextForEvent-test.ts +++ b/test/TextForEvent-test.ts @@ -115,5 +115,15 @@ describe('TextForEvent', () => { expect(plainText).toBe(expectedText); expect(renderComponent(component)).toBe(expectedText); }); + + it("shows generic text when one message was pinned, and another unpinned", () => { + const event = mockPinnedEvent(['message-2'], ['message-1']); + const plainText = textForEvent(event); + const component = renderer.create(textForEvent(event, true)); + + const expectedText = "@foo:example.com changed the pinned messages for the room."; + expect(plainText).toBe(expectedText); + expect(renderComponent(component)).toBe(expectedText); + }); }); });