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

Let TimelinePanel only send a receipt if there is an event #10912

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/structures/TimelinePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,9 @@ class TimelinePanel extends React.Component<IProps, IState> {
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.
//
Expand Down Expand Up @@ -1133,7 +1135,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
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,
Expand Down
12 changes: 12 additions & 0 deletions test/components/structures/TimelinePanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down