From acdbae3e8c5c38b10e0ee4fe9cdb4fe58b515f2f Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Tue, 16 May 2023 13:34:59 +0200 Subject: [PATCH] Let TimelinePanel not send a receipt if there is no event (#10912) --- 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 c921b2e333..b00b6ed132 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 101ae9b716..a77e30b313 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();