diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index 760526e80a2..cf1d7c26ee6 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -14,6 +14,7 @@ import { MEGOLM_ALGORITHM } from "../../src/crypto/olmlib"; import { EventStatus, MatrixEvent } from "../../src/models/event"; import { Preset } from "../../src/@types/partials"; import * as testUtils from "../test-utils"; +import { ReceiptType } from "../../src/@types/read_receipts"; jest.useFakeTimers(); @@ -980,4 +981,44 @@ describe("MatrixClient", function() { client.supportsExperimentalThreads = supportsExperimentalThreads; }); }); + + describe("read-markers and read-receipts", () => { + it("setRoomReadMarkers", () => { + client.setRoomReadMarkersHttpRequest = jest.fn(); + const room = { + hasPendingEvent: jest.fn().mockReturnValue(false), + addLocalEchoReceipt: jest.fn(), + }; + const rrEvent = new MatrixEvent({ event_id: "read_event_id" }); + const rpEvent = new MatrixEvent({ event_id: "read_private_event_id" }); + client.getRoom = () => room; + + client.setRoomReadMarkers( + "room_id", + "read_marker_event_id", + rrEvent, + rpEvent, + ); + + expect(client.setRoomReadMarkersHttpRequest).toHaveBeenCalledWith( + "room_id", + "read_marker_event_id", + "read_event_id", + "read_private_event_id", + ); + expect(room.addLocalEchoReceipt).toHaveBeenCalledTimes(2); + expect(room.addLocalEchoReceipt).toHaveBeenNthCalledWith( + 1, + client.credentials.userId, + rrEvent, + ReceiptType.Read, + ); + expect(room.addLocalEchoReceipt).toHaveBeenNthCalledWith( + 2, + client.credentials.userId, + rpEvent, + ReceiptType.ReadPrivate, + ); + }); + }); }); diff --git a/spec/unit/sync-accumulator.spec.js b/spec/unit/sync-accumulator.spec.js index b089e0cebc1..5fe9a3611b0 100644 --- a/spec/unit/sync-accumulator.spec.js +++ b/spec/unit/sync-accumulator.spec.js @@ -15,6 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { ReceiptType } from "../../src/@types/read_receipts"; import { SyncAccumulator } from "../../src/sync-accumulator"; // The event body & unsigned object get frozen to assert that they don't get altered @@ -294,10 +295,13 @@ describe("SyncAccumulator", function() { room_id: "!foo:bar", content: { "$event1:localhost": { - "m.read": { + [ReceiptType.Read]: { "@alice:localhost": { ts: 1 }, "@bob:localhost": { ts: 2 }, }, + [ReceiptType.ReadPrivate]: { + "@dan:localhost": { ts: 4 }, + }, "some.other.receipt.type": { "@should_be_ignored:localhost": { key: "val" }, }, @@ -309,7 +313,7 @@ describe("SyncAccumulator", function() { room_id: "!foo:bar", content: { "$event2:localhost": { - "m.read": { + [ReceiptType.Read]: { "@bob:localhost": { ts: 2 }, // clobbers event1 receipt "@charlie:localhost": { ts: 3 }, }, @@ -337,12 +341,15 @@ describe("SyncAccumulator", function() { room_id: "!foo:bar", content: { "$event1:localhost": { - "m.read": { + [ReceiptType.Read]: { "@alice:localhost": { ts: 1 }, }, + [ReceiptType.ReadPrivate]: { + "@dan:localhost": { ts: 4 }, + }, }, "$event2:localhost": { - "m.read": { + [ReceiptType.Read]: { "@bob:localhost": { ts: 2 }, "@charlie:localhost": { ts: 3 }, },