Fall back to receipt timestamp if we have no event (react-sdk part) (#10974)
This commit is contained in:
parent
6871667741
commit
67313743fc
2 changed files with 139 additions and 14 deletions
|
@ -321,6 +321,88 @@ describe("Unread", () => {
|
|||
|
||||
expect(doesRoomHaveUnreadMessages(room)).toBe(true);
|
||||
});
|
||||
|
||||
it("returns false when the event for a thread receipt can't be found, but the receipt ts is late", () => {
|
||||
// Given a room that is read
|
||||
let receipt = new MatrixEvent({
|
||||
type: "m.receipt",
|
||||
room_id: "!foo:bar",
|
||||
content: {
|
||||
[event.getId()!]: {
|
||||
[ReceiptType.Read]: {
|
||||
[myId]: { ts: 1 },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
room.addReceipt(receipt);
|
||||
|
||||
// And a thread
|
||||
const { rootEvent, events } = mkThread({ room, client, authorId: myId, participantUserIds: [aliceId] });
|
||||
|
||||
// When we provide a receipt that points at an unknown event,
|
||||
// but its timestamp is after all events in the thread
|
||||
//
|
||||
// (This could happen if we mis-filed a reaction into the main
|
||||
// thread when it should actually have gone into this thread, or
|
||||
// maybe the event is just not loaded for some reason.)
|
||||
const receiptTs = Math.max(...events.map((e) => e.getTs())) + 100;
|
||||
receipt = new MatrixEvent({
|
||||
type: "m.receipt",
|
||||
room_id: "!foo:bar",
|
||||
content: {
|
||||
["UNKNOWN_EVENT_ID"]: {
|
||||
[ReceiptType.Read]: {
|
||||
[myId]: { ts: receiptTs, threadId: rootEvent.getId()! },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
room.addReceipt(receipt);
|
||||
|
||||
expect(doesRoomHaveUnreadMessages(room)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns true when the event for a thread receipt can't be found, and the receipt ts is early", () => {
|
||||
// Given a room that is read
|
||||
let receipt = new MatrixEvent({
|
||||
type: "m.receipt",
|
||||
room_id: "!foo:bar",
|
||||
content: {
|
||||
[event.getId()!]: {
|
||||
[ReceiptType.Read]: {
|
||||
[myId]: { ts: 1 },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
room.addReceipt(receipt);
|
||||
|
||||
// And a thread
|
||||
const { rootEvent, events } = mkThread({ room, client, authorId: myId, participantUserIds: [aliceId] });
|
||||
|
||||
// When we provide a receipt that points at an unknown event,
|
||||
// but its timestamp is before some of the events in the thread
|
||||
//
|
||||
// (This could happen if we mis-filed a reaction into the main
|
||||
// thread when it should actually have gone into this thread, or
|
||||
// maybe the event is just not loaded for some reason.)
|
||||
const receiptTs = (events.at(-1)?.getTs() ?? 0) - 100;
|
||||
receipt = new MatrixEvent({
|
||||
type: "m.receipt",
|
||||
room_id: "!foo:bar",
|
||||
content: {
|
||||
["UNKNOWN_EVENT_ID"]: {
|
||||
[ReceiptType.Read]: {
|
||||
[myId]: { ts: receiptTs, threadId: rootEvent.getId()! },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
room.addReceipt(receipt);
|
||||
|
||||
expect(doesRoomHaveUnreadMessages(room)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("returns true for a room that only contains a hidden event", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue