Skip to content

Commit c951799

Browse files
SimonBrandnergithub-actions[bot]
authored andcommitted
Fix finding event read up to if stable private read receipts is missing (#2585)
Signed-off-by: Šimon Brandner <[email protected]> Signed-off-by: Šimon Brandner <[email protected]> (cherry picked from commit 478270b)
1 parent 1c9d644 commit c951799

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

spec/unit/room.spec.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,25 +2458,43 @@ describe("Room", function() {
24582458
}
24592459
});
24602460

2461-
it("should compare correctly by timestamp", () => {
2462-
for (let i = 1; i <= 3; i++) {
2461+
describe("correctly compares by timestamp", () => {
2462+
it("should correctly compare, if we have all receipts", () => {
2463+
for (let i = 1; i <= 3; i++) {
2464+
room.getUnfilteredTimelineSet = () => ({
2465+
compareEventOrdering: (_1, _2) => null,
2466+
} as EventTimelineSet);
2467+
room.getReadReceiptForUserId = (userId, ignore, receiptType) => {
2468+
if (receiptType === ReceiptType.ReadPrivate) {
2469+
return { eventId: "eventId1", data: { ts: i === 1 ? 1 : 0 } } as IWrappedReceipt;
2470+
}
2471+
if (receiptType === ReceiptType.UnstableReadPrivate) {
2472+
return { eventId: "eventId2", data: { ts: i === 2 ? 1 : 0 } } as IWrappedReceipt;
2473+
}
2474+
if (receiptType === ReceiptType.Read) {
2475+
return { eventId: "eventId3", data: { ts: i === 3 ? 1 : 0 } } as IWrappedReceipt;
2476+
}
2477+
};
2478+
2479+
expect(room.getEventReadUpTo(userA)).toEqual(`eventId${i}`);
2480+
}
2481+
});
2482+
2483+
it("should correctly compare, if private read receipt is missing", () => {
24632484
room.getUnfilteredTimelineSet = () => ({
24642485
compareEventOrdering: (_1, _2) => null,
24652486
} as EventTimelineSet);
24662487
room.getReadReceiptForUserId = (userId, ignore, receiptType) => {
2467-
if (receiptType === ReceiptType.ReadPrivate) {
2468-
return { eventId: "eventId1", data: { ts: i === 1 ? 1 : 0 } } as IWrappedReceipt;
2469-
}
24702488
if (receiptType === ReceiptType.UnstableReadPrivate) {
2471-
return { eventId: "eventId2", data: { ts: i === 2 ? 1 : 0 } } as IWrappedReceipt;
2489+
return { eventId: "eventId1", data: { ts: 0 } } as IWrappedReceipt;
24722490
}
24732491
if (receiptType === ReceiptType.Read) {
2474-
return { eventId: "eventId3", data: { ts: i === 3 ? 1 : 0 } } as IWrappedReceipt;
2492+
return { eventId: "eventId2", data: { ts: 1 } } as IWrappedReceipt;
24752493
}
24762494
};
24772495

2478-
expect(room.getEventReadUpTo(userA)).toEqual(`eventId${i}`);
2479-
}
2496+
expect(room.getEventReadUpTo(userA)).toEqual(`eventId2`);
2497+
});
24802498
});
24812499

24822500
describe("fallback precedence", () => {

src/models/room.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2592,7 +2592,7 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
25922592

25932593
let latest = privateReadReceipt;
25942594
[unstablePrivateReadReceipt, publicReadReceipt].forEach((receipt) => {
2595-
if (receipt?.data?.ts > latest?.data?.ts) {
2595+
if (receipt?.data?.ts > latest?.data?.ts || !latest) {
25962596
latest = receipt;
25972597
}
25982598
});

0 commit comments

Comments
 (0)