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

Commit 64f6390

Browse files
committed
Return only the first 100 pinned messages
1 parent eae9d9e commit 64f6390

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
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([], []);

0 commit comments

Comments
 (0)