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

Commit 52846d1

Browse files
committed
Return only the first 100 pinned messages
1 parent eae9d9e commit 52846d1

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/hooks/usePinnedEvents.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ import PinningUtils from "../utils/PinningUtils";
2727

2828
/**
2929
* Get the pinned event IDs from a room.
30+
* The number of pinned events is limited to 100.
3031
* @param room
3132
*/
3233
function getPinnedEventIds(room?: Room): string[] {
33-
return (
34+
const eventIds: string[] =
3435
room
3536
?.getLiveTimeline()
3637
.getState(EventTimeline.FORWARDS)
3738
?.getStateEvents(EventType.RoomPinnedEvents, "")
38-
?.getContent()?.pinned ?? []
39-
);
39+
?.getContent()?.pinned ?? [];
40+
// Limit the number of pinned events to 100
41+
return eventIds.slice(0, 100);
4042
}
4143

4244
/**

test/components/views/right_panel/PinnedMessagesCard-test.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,21 @@ describe("<PinnedMessagesCard />", () => {
196196
expect(asFragment()).toMatchSnapshot();
197197
});
198198

199+
it("should not show more than 100 messages", async () => {
200+
const events = Array.from({ length: 120 }, (_, i) =>
201+
mkMessage({
202+
event: true,
203+
room: "!room:example.org",
204+
user: "@alice:example.org",
205+
msg: `The message ${i}`,
206+
ts: i,
207+
}),
208+
);
209+
await initPinnedMessagesCard(events, []);
210+
211+
expect(screen.queryAllByRole("listitem")).toHaveLength(100);
212+
});
213+
199214
it("should updates when messages are pinned", async () => {
200215
// Start with nothing pinned
201216
const { addLocalPinEvent, addNonLocalPinEvent } = await initPinnedMessagesCard([], []);

test/components/views/right_panel/__snapshots__/PinnedMessagesCard-test.tsx.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ exports[`<PinnedMessagesCard /> unpin all should not allow to unpinall 1`] = `
358358
aria-label="Open menu"
359359
class="_icon-button_bh2qc_17"
360360
data-state="closed"
361-
id="radix-18"
361+
id="radix-218"
362362
role="button"
363363
style="--cpd-icon-button-size: 24px;"
364364
tabindex="0"
@@ -424,7 +424,7 @@ exports[`<PinnedMessagesCard /> unpin all should not allow to unpinall 1`] = `
424424
aria-label="Open menu"
425425
class="_icon-button_bh2qc_17"
426426
data-state="closed"
427-
id="radix-19"
427+
id="radix-219"
428428
role="button"
429429
style="--cpd-icon-button-size: 24px;"
430430
tabindex="0"

0 commit comments

Comments
 (0)