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

Commit acdbae3

Browse files
authored
Let TimelinePanel not send a receipt if there is no event (#10912)
1 parent da0f072 commit acdbae3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/components/structures/TimelinePanel.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,9 @@ class TimelinePanel extends React.Component<IProps, IState> {
10821082
currentReadReceiptEventIndex: number | null,
10831083
lastReadEvent: MatrixEvent | null,
10841084
lastReadEventIndex: number | null,
1085-
): boolean {
1085+
): lastReadEvent is MatrixEvent {
1086+
if (!lastReadEvent) return false;
1087+
10861088
// We want to avoid sending out read receipts when we are looking at
10871089
// events in the past which are before the latest RR.
10881090
//
@@ -1133,7 +1135,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
11331135
const lastReadEventIndex = this.getLastDisplayedEventIndex({
11341136
ignoreOwn: true,
11351137
});
1136-
const lastReadEvent: MatrixEvent | null = this.state.events[lastReadEventIndex ?? 0];
1138+
const lastReadEvent: MatrixEvent | null = this.state.events[lastReadEventIndex ?? 0] ?? null;
11371139

11381140
const shouldSendReadReceipt = this.shouldSendReadReceipt(
11391141
currentReadReceiptEventId,

test/components/structures/TimelinePanel-test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,18 @@ describe("TimelinePanel", () => {
242242
TimelinePanel.roomReadMarkerTsMap = {};
243243
});
244244

245+
it("when there is no event, it should not send any receipt", async () => {
246+
setUpTimelineSet();
247+
await renderTimelinePanel();
248+
await flushPromises();
249+
250+
// @ts-ignore
251+
await timelinePanel.sendReadReceipts();
252+
253+
expect(client.setRoomReadMarkers).not.toHaveBeenCalled();
254+
expect(client.sendReadReceipt).not.toHaveBeenCalled();
255+
});
256+
245257
describe("when there is a non-threaded timeline", () => {
246258
beforeEach(() => {
247259
setUpTimelineSet();

0 commit comments

Comments
 (0)