Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions spec/unit/room.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2458,25 +2458,43 @@ describe("Room", function() {
}
});

it("should compare correctly by timestamp", () => {
for (let i = 1; i <= 3; i++) {
describe("correctly compares by timestamp", () => {
it("should correctly compare, if we have all receipts", () => {
for (let i = 1; i <= 3; i++) {
room.getUnfilteredTimelineSet = () => ({
compareEventOrdering: (_1, _2) => null,
} as EventTimelineSet);
room.getReadReceiptForUserId = (userId, ignore, receiptType) => {
if (receiptType === ReceiptType.ReadPrivate) {
return { eventId: "eventId1", data: { ts: i === 1 ? 1 : 0 } } as IWrappedReceipt;
}
if (receiptType === ReceiptType.UnstableReadPrivate) {
return { eventId: "eventId2", data: { ts: i === 2 ? 1 : 0 } } as IWrappedReceipt;
}
if (receiptType === ReceiptType.Read) {
return { eventId: "eventId3", data: { ts: i === 3 ? 1 : 0 } } as IWrappedReceipt;
}
};

expect(room.getEventReadUpTo(userA)).toEqual(`eventId${i}`);
}
});

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.ReadPrivate) {
return { eventId: "eventId1", data: { ts: i === 1 ? 1 : 0 } } as IWrappedReceipt;
}
if (receiptType === ReceiptType.UnstableReadPrivate) {
return { eventId: "eventId2", data: { ts: i === 2 ? 1 : 0 } } as IWrappedReceipt;
return { eventId: "eventId1", data: { ts: 0 } } as IWrappedReceipt;
}
if (receiptType === ReceiptType.Read) {
return { eventId: "eventId3", data: { ts: i === 3 ? 1 : 0 } } as IWrappedReceipt;
return { eventId: "eventId2", data: { ts: 1 } } as IWrappedReceipt;
}
};

expect(room.getEventReadUpTo(userA)).toEqual(`eventId${i}`);
}
expect(room.getEventReadUpTo(userA)).toEqual(`eventId2`);
});
});

describe("fallback precedence", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,7 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>

let latest = privateReadReceipt;
[unstablePrivateReadReceipt, publicReadReceipt].forEach((receipt) => {
if (receipt?.data?.ts > latest?.data?.ts) {
if (receipt?.data?.ts > latest?.data?.ts || !latest) {
latest = receipt;
}
});
Expand Down