1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Fix finding event read up to if stable private read receipts is missing (#2585) (#2588)

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
(cherry picked from commit 478270b225)

Co-authored-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
ElementRobot
2022-08-11 13:36:54 +01:00
committed by GitHub
parent 1c9d644a23
commit 0e8bd3f02d
2 changed files with 28 additions and 10 deletions

View File

@@ -2458,7 +2458,8 @@ describe("Room", function() {
} }
}); });
it("should compare correctly by timestamp", () => { describe("correctly compares by timestamp", () => {
it("should correctly compare, if we have all receipts", () => {
for (let i = 1; i <= 3; i++) { for (let i = 1; i <= 3; i++) {
room.getUnfilteredTimelineSet = () => ({ room.getUnfilteredTimelineSet = () => ({
compareEventOrdering: (_1, _2) => null, compareEventOrdering: (_1, _2) => null,
@@ -2479,6 +2480,23 @@ describe("Room", function() {
} }
}); });
it("should correctly compare, if private read receipt is missing", () => {
room.getUnfilteredTimelineSet = () => ({
compareEventOrdering: (_1, _2) => null,
} as EventTimelineSet);
room.getReadReceiptForUserId = (userId, ignore, receiptType) => {
if (receiptType === ReceiptType.UnstableReadPrivate) {
return { eventId: "eventId1", data: { ts: 0 } } as IWrappedReceipt;
}
if (receiptType === ReceiptType.Read) {
return { eventId: "eventId2", data: { ts: 1 } } as IWrappedReceipt;
}
};
expect(room.getEventReadUpTo(userA)).toEqual(`eventId2`);
});
});
describe("fallback precedence", () => { describe("fallback precedence", () => {
beforeAll(() => { beforeAll(() => {
room.getUnfilteredTimelineSet = () => ({ room.getUnfilteredTimelineSet = () => ({

View File

@@ -2592,7 +2592,7 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
let latest = privateReadReceipt; let latest = privateReadReceipt;
[unstablePrivateReadReceipt, publicReadReceipt].forEach((receipt) => { [unstablePrivateReadReceipt, publicReadReceipt].forEach((receipt) => {
if (receipt?.data?.ts > latest?.data?.ts) { if (receipt?.data?.ts > latest?.data?.ts || !latest) {
latest = receipt; latest = receipt;
} }
}); });