Consider the unthreaded read receipt for Unread dot state (#11117)

* Consider the unthreaded read receipt for Unread dot state also

* Add tests

* Fix strict types
This commit is contained in:
Michael Telatynski 2023-06-21 16:07:16 +01:00 committed by GitHub
parent 9b5b053148
commit 767cd628f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 12 deletions

View file

@ -159,15 +159,13 @@ function makeHasReceipt(
// If we found an event matching our receipt, then it's easy: this event
// has a receipt if its ID is the same as the one in the receipt.
return (ev) => ev.getId() == readUpToId;
} else {
// If we didn't, we have to guess by saying if this event is before the
// receipt's ts, then it we pretend it has a receipt.
const receipt = roomOrThread.getReadReceiptForUserId(myUserId);
if (receipt) {
const receiptTimestamp = receipt.data.ts;
return (ev) => ev.getTs() < receiptTimestamp;
} else {
return (_ev) => false;
}
}
// If we didn't, we have to guess by saying if this event is before the
// receipt's ts, then it we pretend it has a receipt.
const receiptTs = roomOrThread.getReadReceiptForUserId(myUserId)?.data.ts ?? 0;
const unthreadedReceiptTs = roomOrThread.getLastUnthreadedReceiptFor(myUserId)?.ts ?? 0;
// We pick the more recent of the two receipts as the latest
const receiptTimestamp = Math.max(receiptTs, unthreadedReceiptTs);
return (ev) => ev.getTs() < receiptTimestamp;
}