From 0e103a3cd1c43d871ef3b1e338c911549dc11942 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Tue, 16 May 2023 13:08:32 +0200 Subject: [PATCH] Let TimelinePanel not send a receipt if there is no event --- src/components/structures/TimelinePanel.tsx | 6 ++++-- test/components/structures/TimelinePanel-test.tsx | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/components/structures/TimelinePanel.tsx b/src/components/structures/TimelinePanel.tsx index c921b2e3330..b00b6ed132a 100644 --- a/src/components/structures/TimelinePanel.tsx +++ b/src/components/structures/TimelinePanel.tsx @@ -1082,7 +1082,9 @@ class TimelinePanel extends React.Component { currentReadReceiptEventIndex: number | null, lastReadEvent: MatrixEvent | null, lastReadEventIndex: number | null, - ): boolean { + ): lastReadEvent is MatrixEvent { + if (!lastReadEvent) return false; + // We want to avoid sending out read receipts when we are looking at // events in the past which are before the latest RR. // @@ -1133,7 +1135,7 @@ class TimelinePanel extends React.Component { const lastReadEventIndex = this.getLastDisplayedEventIndex({ ignoreOwn: true, }); - const lastReadEvent: MatrixEvent | null = this.state.events[lastReadEventIndex ?? 0]; + const lastReadEvent: MatrixEvent | null = this.state.events[lastReadEventIndex ?? 0] ?? null; const shouldSendReadReceipt = this.shouldSendReadReceipt( currentReadReceiptEventId, diff --git a/test/components/structures/TimelinePanel-test.tsx b/test/components/structures/TimelinePanel-test.tsx index 101ae9b716e..a77e30b313b 100644 --- a/test/components/structures/TimelinePanel-test.tsx +++ b/test/components/structures/TimelinePanel-test.tsx @@ -242,6 +242,18 @@ describe("TimelinePanel", () => { TimelinePanel.roomReadMarkerTsMap = {}; }); + it("when there is no event, it should not send any receipt", async () => { + setUpTimelineSet(); + await renderTimelinePanel(); + await flushPromises(); + + // @ts-ignore + await timelinePanel.sendReadReceipts(); + + expect(client.setRoomReadMarkers).not.toHaveBeenCalled(); + expect(client.sendReadReceipt).not.toHaveBeenCalled(); + }); + describe("when there is a non-threaded timeline", () => { beforeEach(() => { setUpTimelineSet();