Skip to content

Commit

Permalink
Fix finding event read up to if stable private read receipts is missi…
Browse files Browse the repository at this point in the history
…ng (#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 478270b)

Co-authored-by: Šimon Brandner <simon.bra.ag@gmail.com>
  • Loading branch information
RiotRobot and SimonBrandner authored Aug 11, 2022
1 parent 1c9d644 commit 0e8bd3f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
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

0 comments on commit 0e8bd3f

Please sign in to comment.