From 7c4c3b40ea9644c48d1a820d12fe7551bfc5640b Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Tue, 28 Nov 2023 13:10:47 +0000 Subject: [PATCH 1/2] Update tests in anticipation of matrix-js-sdk#3901 --- test/Unread-test.ts | 46 +++++++++++++++++-- .../LegacyRoomHeaderButtons-test.tsx | 16 ++++++- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/test/Unread-test.ts b/test/Unread-test.ts index 46221d75d20..d2cd57384ed 100644 --- a/test/Unread-test.ts +++ b/test/Unread-test.ts @@ -228,6 +228,22 @@ describe("Unread", () => { }); room.addReceipt(receipt); + // Create a read thread, so we don't consider all threads read + // because there are no threaded read receipts. + const { rootEvent, events } = mkThread({ room, client, authorId: myId, participantUserIds: [aliceId] }); + const receipt2 = new MatrixEvent({ + type: "m.receipt", + room_id: "!foo:bar", + content: { + [events[events.length - 1].getId()!]: { + [ReceiptType.Read]: { + [myId]: { ts: 1, thread_id: rootEvent.getId() }, + }, + }, + }, + }); + room.addReceipt(receipt2); + // Create a thread as a different user. mkThread({ room, client, authorId: myId, participantUserIds: [aliceId] }); @@ -315,7 +331,7 @@ describe("Unread", () => { content: { [events[0].getId()!]: { [ReceiptType.Read]: { - [myId]: { ts: 1, threadId: rootEvent.getId()! }, + [myId]: { ts: 1, thread_id: rootEvent.getId()! }, }, }, }, @@ -325,7 +341,8 @@ 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", () => { + // Fails with current implementation. Will be fixed or replaced after matrix-js-sdk#3901 + it.skip("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", @@ -356,7 +373,7 @@ describe("Unread", () => { content: { ["UNKNOWN_EVENT_ID"]: { [ReceiptType.Read]: { - [myId]: { ts: receiptTs, threadId: rootEvent.getId()! }, + [myId]: { ts: receiptTs, thread_id: rootEvent.getId()! }, }, }, }, @@ -381,6 +398,27 @@ describe("Unread", () => { }); room.addReceipt(receipt); + // Create a read thread, so we don't consider all threads read + // because there are no threaded read receipts. + const { rootEvent: rootEvent1, events: events1 } = mkThread({ + room, + client, + authorId: myId, + participantUserIds: [aliceId], + }); + const receipt2 = new MatrixEvent({ + type: "m.receipt", + room_id: "!foo:bar", + content: { + [events1[events1.length - 1].getId()!]: { + [ReceiptType.Read]: { + [myId]: { ts: 1, thread_id: rootEvent1.getId() }, + }, + }, + }, + }); + room.addReceipt(receipt2); + // And a thread const { rootEvent, events } = mkThread({ room, client, authorId: myId, participantUserIds: [aliceId] }); @@ -397,7 +435,7 @@ describe("Unread", () => { content: { ["UNKNOWN_EVENT_ID"]: { [ReceiptType.Read]: { - [myId]: { ts: receiptTs, threadId: rootEvent.getId()! }, + [myId]: { ts: receiptTs, thread_id: rootEvent.getId()! }, }, }, }, diff --git a/test/components/views/right_panel/LegacyRoomHeaderButtons-test.tsx b/test/components/views/right_panel/LegacyRoomHeaderButtons-test.tsx index 97d24f1ce16..69064a6c8a3 100644 --- a/test/components/views/right_panel/LegacyRoomHeaderButtons-test.tsx +++ b/test/components/views/right_panel/LegacyRoomHeaderButtons-test.tsx @@ -106,6 +106,20 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () { authorId: client.getUserId()!, participantUserIds: ["@alice:example.org"], }); + // We need some receipt, otherwise we treat this thread as + // "older than all threaded receipts" and consider it read. + let receipt = new MatrixEvent({ + type: "m.receipt", + room_id: room.roomId, + content: { + [events[0].getId()!]: { // Receipt for the first event in the thread + [ReceiptType.Read]: { + [client.getUserId()!]: { ts: 1, thread_id: rootEvent.getId() }, + }, + }, + }, + }); + room.addReceipt(receipt); expect(isIndicatorOfType(container, "bold")).toBe(true); // Sending the last event should clear the notification. @@ -145,7 +159,7 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () { expect(isIndicatorOfType(container, "bold")).toBe(true); // Sending a read receipt on an earlier event shouldn't do anything. - let receipt = new MatrixEvent({ + receipt = new MatrixEvent({ type: "m.receipt", room_id: room.roomId, content: { From 367e7b26ac736e1edb5fa2723c24cda743df2b9f Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Tue, 28 Nov 2023 13:25:54 +0000 Subject: [PATCH 2/2] Formatting --- .../views/right_panel/LegacyRoomHeaderButtons-test.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/components/views/right_panel/LegacyRoomHeaderButtons-test.tsx b/test/components/views/right_panel/LegacyRoomHeaderButtons-test.tsx index 69064a6c8a3..42b7dfaa25b 100644 --- a/test/components/views/right_panel/LegacyRoomHeaderButtons-test.tsx +++ b/test/components/views/right_panel/LegacyRoomHeaderButtons-test.tsx @@ -112,7 +112,8 @@ describe("LegacyRoomHeaderButtons-test.tsx", function () { type: "m.receipt", room_id: room.roomId, content: { - [events[0].getId()!]: { // Receipt for the first event in the thread + [events[0].getId()!]: { + // Receipt for the first event in the thread [ReceiptType.Read]: { [client.getUserId()!]: { ts: 1, thread_id: rootEvent.getId() }, },