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

Commit

Permalink
Handle promises
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed May 12, 2023
1 parent 476df9c commit af38337
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/components/structures/TimelinePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
const readMarkerEvent = this.props.timelineSet.findEventById(readMarkerEventId);

if (readMarkerEvent) {
proms.push(await this.sendReadMarker(client, readMarkerEvent));
proms.push(this.sendReadMarker(client, readMarkerEvent));
}
}

Expand Down Expand Up @@ -1160,7 +1160,7 @@ class TimelinePanel extends React.Component<IProps, IState> {

// if the read marker is on the screen, we can now assume we've caught up to the end
// of the screen, so move the marker down to the bottom of the screen.
private updateReadMarker = (): void => {
private updateReadMarker = async (): Promise<void> => {
if (!this.props.manageReadMarkers) return;
if (this.getReadMarkerPosition() === 1) {
// the read marker is at an event below the viewport,
Expand Down Expand Up @@ -1189,7 +1189,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
}

// Send the updated read marker (along with read receipt) to the server
this.sendReadReceipts();
await this.sendReadReceipts();
};

// advance the read marker past any events we sent ourselves.
Expand Down Expand Up @@ -1277,7 +1277,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
/**
* update the read-up-to marker to match the read receipt
*/
public forgetReadMarker = (): void => {
public forgetReadMarker = async (): Promise<void> => {
if (!this.props.manageReadMarkers) return;

// Find the read receipt - we will set the read marker to this
Expand All @@ -1299,7 +1299,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
this.setReadMarker(rmId, rmTs);

// Send the receipts to the server immediately (don't wait for activity)
this.sendReadReceipts();
await this.sendReadReceipts();
};

/* return true if the content is fully scrolled down and we are
Expand Down Expand Up @@ -1492,7 +1492,9 @@ class TimelinePanel extends React.Component<IProps, IState> {
}

if (this.props.sendReadReceiptOnLoad) {
this.sendReadReceipts();
this.sendReadReceipts().catch((err) => {
logger.warn("Error sending receipts on load", err);
});
}
},
);
Expand Down
11 changes: 4 additions & 7 deletions test/components/structures/TimelinePanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ describe("TimelinePanel", () => {
// @ts-ignore
await timelinePanel.sendReadReceipts();
// @ts-ignore Simulate user activity by calling updateReadMarker on the TimelinePanel.
timelinePanel.updateReadMarker();

await flushPromises();
await timelinePanel.updateReadMarker();
});

it("should send a fully read marker and a public receipt", async () => {
Expand All @@ -202,7 +200,7 @@ describe("TimelinePanel", () => {
client.sendReadReceipt.mockClear();

// @ts-ignore Simulate user activity by calling updateReadMarker on the TimelinePanel.
timelinePanel.updateReadMarker();
await timelinePanel.updateReadMarker();
});

it("should not send receipts again", () => {
Expand All @@ -212,8 +210,7 @@ describe("TimelinePanel", () => {
it("and forgetting the read markers, should send the stored marker again", async () => {
timelineSet.addLiveEvent(ev2, {});
room.addEphemeralEvents([newReceipt(ev2.getId()!, userId, 222, 200)]);
timelinePanel.forgetReadMarker();
await flushPromises();
await timelinePanel.forgetReadMarker();
expect(client.sendReadReceipt).toHaveBeenCalledWith(ev2, ReceiptType.FullyRead, true);
});
});
Expand Down Expand Up @@ -251,7 +248,7 @@ describe("TimelinePanel", () => {
client.sendReadReceipt.mockClear();

// @ts-ignore simulate user activity
timelinePanel.updateReadMarker();
await timelinePanel.updateReadMarker();

// It should not send the receipt again.
expect(client.sendReadReceipt).not.toHaveBeenCalledWith(ev1, ReceiptType.ReadPrivate);
Expand Down

0 comments on commit af38337

Please sign in to comment.