You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
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:
@@ -2458,25 +2458,43 @@ describe("Room", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should compare correctly by timestamp", () => {
|
describe("correctly compares by timestamp", () => {
|
||||||
for (let i = 1; i <= 3; i++) {
|
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 = () => ({
|
room.getUnfilteredTimelineSet = () => ({
|
||||||
compareEventOrdering: (_1, _2) => null,
|
compareEventOrdering: (_1, _2) => null,
|
||||||
} as EventTimelineSet);
|
} as EventTimelineSet);
|
||||||
room.getReadReceiptForUserId = (userId, ignore, receiptType) => {
|
room.getReadReceiptForUserId = (userId, ignore, receiptType) => {
|
||||||
if (receiptType === ReceiptType.ReadPrivate) {
|
|
||||||
return { eventId: "eventId1", data: { ts: i === 1 ? 1 : 0 } } as IWrappedReceipt;
|
|
||||||
}
|
|
||||||
if (receiptType === ReceiptType.UnstableReadPrivate) {
|
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) {
|
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", () => {
|
describe("fallback precedence", () => {
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user