From 8d58b875285c7e7ab9f57613bdb9d916ad64f087 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 8 Feb 2022 12:28:48 +0000 Subject: [PATCH] Fix issue with rooms not getting marked as unread due to bad handling fake receipts --- src/models/room.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/models/room.ts b/src/models/room.ts index ab42b45c539..9c59ae88b05 100644 --- a/src/models/room.ts +++ b/src/models/room.ts @@ -2083,7 +2083,11 @@ export class Room extends EventEmitter { const pair = this.receipts[receiptType][userId]; - const existingReceipt = pair[ReceiptPairSyntheticIndex] ?? pair[ReceiptPairRealIndex]; + let existingReceipt = pair[ReceiptPairRealIndex]; + if (fake && !existingReceipt) { + existingReceipt = pair[ReceiptPairSyntheticIndex]; + } + 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. @@ -2100,8 +2104,10 @@ export class Room extends EventEmitter { }; // we don't bother caching just real receipts by event ID as there's nothing that would read it. - if (existingReceipt && this.receiptCacheByEventId[existingReceipt.eventId]) { - const previousEventId = existingReceipt.eventId; + const cachedReceipt = pair[ReceiptPairSyntheticIndex] ?? pair[ReceiptPairRealIndex]; + // clean up any previous cache entry + if (cachedReceipt && this.receiptCacheByEventId[cachedReceipt.eventId]) { + const previousEventId = cachedReceipt.eventId; // Remove the receipt we're about to clobber out of existence from the cache this.receiptCacheByEventId[previousEventId] = ( this.receiptCacheByEventId[previousEventId].filter(r => { @@ -2114,6 +2120,7 @@ export class Room extends EventEmitter { } } + // cache the new one if (!this.receiptCacheByEventId[eventId]) { this.receiptCacheByEventId[eventId] = []; }