Skip to content

Commit

Permalink
Fix edge cases around RR calculations (#2160)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy committed Feb 7, 2022
1 parent 12afcd3 commit 07171a9
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2083,12 +2083,12 @@ export class Room extends EventEmitter {

const pair = this.receipts[receiptType][userId];

const existingMatchingReceipt = fake ? pair[ReceiptPairSyntheticIndex] : pair[ReceiptPairRealIndex];
if (existingMatchingReceipt) {
const existingReceipt = pair[ReceiptPairSyntheticIndex] ?? pair[ReceiptPairRealIndex];
if (existingReceipt) {
// we only want to add this receipt if we think it is later than the one we already have.
// This is managed server-side, but because we synthesize RRs locally we have to do it here too.
const ordering = this.getUnfilteredTimelineSet().compareEventOrdering(
existingMatchingReceipt.eventId, eventId);
existingReceipt.eventId, eventId);
if (ordering !== null && ordering >= 0) {
return;
}
Expand All @@ -2100,7 +2100,6 @@ export class Room extends EventEmitter {
};

// we don't bother caching just real receipts by event ID as there's nothing that would read it.
const existingReceipt = pair[ReceiptPairSyntheticIndex] ?? pair[ReceiptPairRealIndex];
if (existingReceipt && this.receiptCacheByEventId[existingReceipt.eventId]) {
const previousEventId = existingReceipt.eventId;
// Remove the receipt we're about to clobber out of existence from the cache
Expand Down

0 comments on commit 07171a9

Please sign in to comment.