Skip to content

Commit

Permalink
Only add local receipt if it's after existing receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalaam committed May 25, 2023
1 parent a2d1dee commit 63c530d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/models/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,33 @@ export class Thread extends ReadReceipt<EmittedEvents, EventHandlerMap> {
): void => {
// Add a synthesized receipt when paginating forward in the timeline
if (!toStartOfTimeline) {
room!.addLocalEchoReceipt(event.getSender()!, event, ReceiptType.Read);
const sender = event.getSender();
if (sender && room && this.shouldSendLocalEchoReceipt(sender, event)) {
room.addLocalEchoReceipt(sender, event, ReceiptType.Read);
}
}
this.onEcho(event, toStartOfTimeline ?? false);
};

private shouldSendLocalEchoReceipt(sender: string, event: MatrixEvent): boolean {
const recursionSupport = this.client.canSupport.get(Feature.RelationsRecursion) ?? ServerSupport.Unsupported;

if (recursionSupport === ServerSupport.Unsupported) {
// Normally we add a local receipt, but if we don't have
// recursion support, then events may arrive out of order, so we
// only create a receipt if it's after our existing receipt.
const oldReceiptEventId = this.getReadReceiptForUserId(sender)?.eventId;
if (oldReceiptEventId) {
const receiptEvent = this.findEventById(oldReceiptEventId);
if (receiptEvent && receiptEvent.getTs() > event.getTs()) {
return false;
}
}
}

return true;
}

private onLocalEcho = (event: MatrixEvent): void => {
this.onEcho(event, false);
};
Expand Down

0 comments on commit 63c530d

Please sign in to comment.