From 044eaf7eb598ca4609c740f51ab1863f40881c32 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 6 Nov 2024 14:55:21 +0000 Subject: [PATCH 1/2] Update calls to addEventToTimeline and addLiveEvents for new signature Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/FilePanel.tsx | 6 ++- src/indexing/EventIndex.ts | 6 ++- src/utils/dm/createDmLocalRoom.ts | 2 +- test/test-utils/call.ts | 50 +++++++++++-------- test/test-utils/threads.ts | 2 +- test/unit-tests/Notifier-test.ts | 3 +- test/unit-tests/RoomNotifs-test.ts | 10 ++-- test/unit-tests/Unread-test.ts | 14 +++--- .../components/structures/RoomView-test.tsx | 24 +++++---- .../structures/ThreadPanel-test.tsx | 12 ++--- .../structures/TimelinePanel-test.tsx | 35 ++++++++----- .../RoomGeneralContextMenu-test.tsx | 2 +- .../views/dialogs/InviteDialog-test.tsx | 23 +++++---- .../components/views/elements/Pill-test.tsx | 2 +- .../views/elements/RoomTopic-test.tsx | 2 +- .../UnreadNotificationBadge-test.tsx | 2 +- .../views/rooms/RoomHeader-test.tsx | 2 +- .../views/settings/Notifications-test.tsx | 2 +- .../notifications/Notifications2-test.tsx | 2 +- .../events/EventTileFactory-test.ts | 2 +- test/unit-tests/models/Call-test.ts | 2 +- .../unit-tests/stores/MemberListStore-test.ts | 1 + test/unit-tests/stores/RoomViewStore-test.ts | 2 +- .../room-list/MessagePreviewStore-test.ts | 2 +- .../algorithms/RecentAlgorithm-test.ts | 18 +++---- .../previews/ReactionEventPreview-test.ts | 4 +- test/unit-tests/useTopic-test.tsx | 4 +- .../utils/exportUtils/HTMLExport-test.ts | 27 +++++----- test/unit-tests/utils/notifications-test.ts | 6 +-- .../components/VoiceBroadcastBody-test.tsx | 6 +-- .../models/VoiceBroadcastPlayback-test.tsx | 14 +++--- .../utils/hasRoomLiveVoiceBroadcast-test.ts | 2 +- .../utils/isRelatedToVoiceBroadcast-test.ts | 4 +- .../utils/retrieveStartedInfoEvent-test.ts | 2 +- 34 files changed, 166 insertions(+), 131 deletions(-) diff --git a/src/components/structures/FilePanel.tsx b/src/components/structures/FilePanel.tsx index 74a91d8cbc..07a20315f5 100644 --- a/src/components/structures/FilePanel.tsx +++ b/src/components/structures/FilePanel.tsx @@ -104,7 +104,11 @@ class FilePanel extends React.Component { } if (!this.state.timelineSet.eventIdToTimeline(ev.getId()!)) { - this.state.timelineSet.addEventToTimeline(ev, timeline, false); + this.state.timelineSet.addEventToTimeline(ev, timeline, { + fromCache: false, + addToState: false, + toStartOfTimeline: false, + }); } } diff --git a/src/indexing/EventIndex.ts b/src/indexing/EventIndex.ts index ec3935cd68..0b1a29e9a4 100644 --- a/src/indexing/EventIndex.ts +++ b/src/indexing/EventIndex.ts @@ -820,7 +820,11 @@ export default class EventIndex extends EventEmitter { // Add the events to the timeline of the file panel. matrixEvents.forEach((e) => { if (!timelineSet.eventIdToTimeline(e.getId()!)) { - timelineSet.addEventToTimeline(e, timeline, direction == EventTimeline.BACKWARDS); + timelineSet.addEventToTimeline(e, timeline, { + toStartOfTimeline: direction == EventTimeline.BACKWARDS, + fromCache: false, + addToState: false, + }); } }); diff --git a/src/utils/dm/createDmLocalRoom.ts b/src/utils/dm/createDmLocalRoom.ts index 6d6cf0712b..0a3d312368 100644 --- a/src/utils/dm/createDmLocalRoom.ts +++ b/src/utils/dm/createDmLocalRoom.ts @@ -109,7 +109,7 @@ export async function createDmLocalRoom(client: MatrixClient, targets: Member[]) localRoom.targets = targets; localRoom.updateMyMembership(KnownMembership.Join); - localRoom.addLiveEvents(events); + localRoom.addLiveEvents(events, { addToState: true }); localRoom.currentState.setStateEvents(events); localRoom.name = localRoom.getDefaultRoomName(client.getUserId()!); client.store.storeRoom(localRoom); diff --git a/test/test-utils/call.ts b/test/test-utils/call.ts index 0262e5537f..df87fcaa55 100644 --- a/test/test-utils/call.ts +++ b/test/test-utils/call.ts @@ -44,17 +44,20 @@ export class MockedCall extends Call { } public static create(room: Room, id: string) { - room.addLiveEvents([ - mkEvent({ - event: true, - type: this.EVENT_TYPE, - room: room.roomId, - user: "@alice:example.org", - content: { "m.type": "m.video", "m.intent": "m.prompt" }, - skey: id, - ts: Date.now(), - }), - ]); + room.addLiveEvents( + [ + mkEvent({ + event: true, + type: this.EVENT_TYPE, + room: room.roomId, + user: "@alice:example.org", + content: { "m.type": "m.video", "m.intent": "m.prompt" }, + skey: id, + ts: Date.now(), + }), + ], + { addToState: true }, + ); // @ts-ignore deliberately calling a private method // Let CallStore know that a call might now exist CallStore.instance.updateRoom(room); @@ -81,17 +84,20 @@ export class MockedCall extends Call { public destroy() { // Terminate the call for good measure - this.room.addLiveEvents([ - mkEvent({ - event: true, - type: MockedCall.EVENT_TYPE, - room: this.room.roomId, - user: "@alice:example.org", - content: { ...this.event.getContent(), "m.terminated": "Call ended" }, - skey: this.widget.id, - ts: Date.now(), - }), - ]); + this.room.addLiveEvents( + [ + mkEvent({ + event: true, + type: MockedCall.EVENT_TYPE, + room: this.room.roomId, + user: "@alice:example.org", + content: { ...this.event.getContent(), "m.terminated": "Call ended" }, + skey: this.widget.id, + ts: Date.now(), + }), + ], + { addToState: true }, + ); super.destroy(); } diff --git a/test/test-utils/threads.ts b/test/test-utils/threads.ts index d2459653e5..83313b1b8d 100644 --- a/test/test-utils/threads.ts +++ b/test/test-utils/threads.ts @@ -157,6 +157,6 @@ export const populateThread = async ({ // that it is already loaded, and send the events again to the room // so they are added to the thread timeline. ret.thread.initialEventsFetched = true; - await room.addLiveEvents(ret.events); + await room.addLiveEvents(ret.events, { addToState: false }); return ret; }; diff --git a/test/unit-tests/Notifier-test.ts b/test/unit-tests/Notifier-test.ts index 7bfde2afb3..2833659792 100644 --- a/test/unit-tests/Notifier-test.ts +++ b/test/unit-tests/Notifier-test.ts @@ -624,8 +624,7 @@ describe("Notifier", () => { content: { body: "this is a thread root" }, }), testRoom.threadsTimelineSets[0]!.getLiveTimeline(), - false, - false, + { toStartOfTimeline: false, fromCache: false, addToState: true }, ); expect(fn).not.toHaveBeenCalled(); diff --git a/test/unit-tests/RoomNotifs-test.ts b/test/unit-tests/RoomNotifs-test.ts index 51416ab7fd..65089eba94 100644 --- a/test/unit-tests/RoomNotifs-test.ts +++ b/test/unit-tests/RoomNotifs-test.ts @@ -147,7 +147,7 @@ describe("RoomNotifs test", () => { const itShouldCountPredecessorHighlightWhenThereIsAPredecessorInTheCreateEvent = (): void => { it("and there is a predecessor in the create event, it should count predecessor highlight", () => { - room.addLiveEvents([mkCreateEvent(OLD_ROOM_ID)]); + room.addLiveEvents([mkCreateEvent(OLD_ROOM_ID)], { addToState: true }); expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8); expect(getUnreadNotificationCount(room, NotificationCountType.Highlight, false)).toBe(7); @@ -157,7 +157,7 @@ describe("RoomNotifs test", () => { const itShouldCountPredecessorHighlightWhenThereIsAPredecessorEvent = (): void => { it("and there is a predecessor event, it should count predecessor highlight", () => { client.getVisibleRooms(); - room.addLiveEvents([mkCreateEvent(OLD_ROOM_ID)]); + room.addLiveEvents([mkCreateEvent(OLD_ROOM_ID)], { addToState: true }); upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]); expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8); @@ -185,7 +185,7 @@ describe("RoomNotifs test", () => { itShouldCountPredecessorHighlightWhenThereIsAPredecessorEvent(); it("and there is only a predecessor event, it should not count predecessor highlight", () => { - room.addLiveEvents([mkCreateEvent()]); + room.addLiveEvents([mkCreateEvent()], { addToState: true }); upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]); expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(2); @@ -204,7 +204,7 @@ describe("RoomNotifs test", () => { itShouldCountPredecessorHighlightWhenThereIsAPredecessorEvent(); it("and there is only a predecessor event, it should count predecessor highlight", () => { - room.addLiveEvents([mkCreateEvent()]); + room.addLiveEvents([mkCreateEvent()], { addToState: true }); upsertRoomStateEvents(room, [mkPredecessorEvent(OLD_ROOM_ID)]); expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(8); @@ -212,7 +212,7 @@ describe("RoomNotifs test", () => { }); it("and there is an unknown room in the predecessor event, it should not count predecessor highlight", () => { - room.addLiveEvents([mkCreateEvent()]); + room.addLiveEvents([mkCreateEvent()], { addToState: true }); upsertRoomStateEvents(room, [mkPredecessorEvent("!unknon:example.com")]); expect(getUnreadNotificationCount(room, NotificationCountType.Total, false)).toBe(2); diff --git a/test/unit-tests/Unread-test.ts b/test/unit-tests/Unread-test.ts index 8719da06ef..15d3dab8f5 100644 --- a/test/unit-tests/Unread-test.ts +++ b/test/unit-tests/Unread-test.ts @@ -138,7 +138,7 @@ describe("Unread", () => { room: roomId, content: {}, }); - room.addLiveEvents([event]); + room.addLiveEvents([event], { addToState: true }); // Don't care about the code path of hidden events. mocked(haveRendererForEvent).mockClear().mockReturnValue(true); @@ -157,7 +157,7 @@ describe("Unread", () => { content: {}, }); // Only for timeline events. - room.addLiveEvents([event]); + room.addLiveEvents([event], { addToState: true }); expect(doesRoomHaveUnreadMessages(room, false)).toBe(false); }); @@ -201,7 +201,7 @@ describe("Unread", () => { content: {}, }); // Only for timeline events. - room.addLiveEvents([event2]); + room.addLiveEvents([event2], { addToState: true }); expect(doesRoomHaveUnreadMessages(room, false)).toBe(true); }); @@ -403,7 +403,7 @@ describe("Unread", () => { redactedEvent.makeRedacted(redactedEvent, room); console.log("Event Id", redactedEvent.getId()); // Only for timeline events. - room.addLiveEvents([redactedEvent]); + room.addLiveEvents([redactedEvent], { addToState: true }); expect(doesRoomHaveUnreadMessages(room, true)).toBe(true); expect(logger.warn).toHaveBeenCalledWith( @@ -448,7 +448,7 @@ describe("Unread", () => { room: roomId, content: {}, }); - room.addLiveEvents([event]); + room.addLiveEvents([event], { addToState: true }); }); it("an unthreaded receipt for the event makes the room read", () => { @@ -502,7 +502,7 @@ describe("Unread", () => { ts: 100, currentUserId: myId, }); - room.addLiveEvents(events); + room.addLiveEvents(events, { addToState: true }); threadEvent = events[1]; }); @@ -555,7 +555,7 @@ describe("Unread", () => { room: roomId, content: {}, }); - room.addLiveEvents([event]); + room.addLiveEvents([event], { addToState: true }); // It still returns false expect(doesRoomHaveUnreadThreads(room)).toBe(false); diff --git a/test/unit-tests/components/structures/RoomView-test.tsx b/test/unit-tests/components/structures/RoomView-test.tsx index b6a0f28637..dfc663dc23 100644 --- a/test/unit-tests/components/structures/RoomView-test.tsx +++ b/test/unit-tests/components/structures/RoomView-test.tsx @@ -249,15 +249,19 @@ describe("RoomView", () => { cli.isRoomEncrypted.mockReturnValue(true); // and fake an encryption event into the room to prompt it to re-check - room.addLiveEvents([ - new MatrixEvent({ - type: "m.room.encryption", - sender: cli.getUserId()!, - content: {}, - event_id: "someid", - room_id: room.roomId, - }), - ]); + room.addLiveEvents( + [ + new MatrixEvent({ + type: "m.room.encryption", + sender: cli.getUserId()!, + content: {}, + event_id: "someid", + room_id: room.roomId, + state_key: "", + }), + ], + { addToState: true }, + ); // URL previews should now be disabled expect(roomViewInstance.state.showUrlPreview).toBe(false); @@ -440,7 +444,7 @@ describe("RoomView", () => { skey: id, ts, }); - room.addLiveEvents([widgetEvent]); + room.addLiveEvents([widgetEvent], { addToState: true }); room.currentState.setStateEvents([widgetEvent]); cli.emit(RoomStateEvent.Events, widgetEvent, room.currentState, null); await flushPromises(); diff --git a/test/unit-tests/components/structures/ThreadPanel-test.tsx b/test/unit-tests/components/structures/ThreadPanel-test.tsx index 1b4d59d9af..ddb6058759 100644 --- a/test/unit-tests/components/structures/ThreadPanel-test.tsx +++ b/test/unit-tests/components/structures/ThreadPanel-test.tsx @@ -209,11 +209,11 @@ describe("ThreadPanel", () => { return event ? Promise.resolve(event) : Promise.reject(); }); const [allThreads, myThreads] = room.threadsTimelineSets; - allThreads!.addLiveEvent(otherThread.rootEvent); - allThreads!.addLiveEvent(mixedThread.rootEvent); - allThreads!.addLiveEvent(ownThread.rootEvent); - myThreads!.addLiveEvent(mixedThread.rootEvent); - myThreads!.addLiveEvent(ownThread.rootEvent); + allThreads!.addLiveEvent(otherThread.rootEvent, { addToState: true }); + allThreads!.addLiveEvent(mixedThread.rootEvent, { addToState: true }); + allThreads!.addLiveEvent(ownThread.rootEvent, { addToState: true }); + myThreads!.addLiveEvent(mixedThread.rootEvent, { addToState: true }); + myThreads!.addLiveEvent(ownThread.rootEvent, { addToState: true }); let events: EventData[] = []; const renderResult = render(); @@ -259,7 +259,7 @@ describe("ThreadPanel", () => { return event ? Promise.resolve(event) : Promise.reject(); }); const [allThreads] = room.threadsTimelineSets; - allThreads!.addLiveEvent(otherThread.rootEvent); + allThreads!.addLiveEvent(otherThread.rootEvent, { addToState: true }); let events: EventData[] = []; const renderResult = render(); diff --git a/test/unit-tests/components/structures/TimelinePanel-test.tsx b/test/unit-tests/components/structures/TimelinePanel-test.tsx index 4a66351779..8f52c1bf25 100644 --- a/test/unit-tests/components/structures/TimelinePanel-test.tsx +++ b/test/unit-tests/components/structures/TimelinePanel-test.tsx @@ -66,7 +66,7 @@ const mkTimeline = (room: Room, events: MatrixEvent[]): [EventTimeline, EventTim getPendingEvents: () => [] as MatrixEvent[], } as unknown as EventTimelineSet; const timeline = new EventTimeline(timelineSet); - events.forEach((event) => timeline.addEvent(event, { toStartOfTimeline: false })); + events.forEach((event) => timeline.addEvent(event, { toStartOfTimeline: false, addToState: true })); return [timeline, timelineSet]; }; @@ -150,9 +150,11 @@ const setupPagination = ( mocked(client).paginateEventTimeline.mockImplementation(async (tl, { backwards }) => { if (tl === timeline) { if (backwards) { - forEachRight(previousPage ?? [], (event) => tl.addEvent(event, { toStartOfTimeline: true })); + forEachRight(previousPage ?? [], (event) => + tl.addEvent(event, { toStartOfTimeline: true, addToState: true }), + ); } else { - (nextPage ?? []).forEach((event) => tl.addEvent(event, { toStartOfTimeline: false })); + (nextPage ?? []).forEach((event) => tl.addEvent(event, { toStartOfTimeline: false, addToState: true })); } // Prevent any further pagination attempts in this direction tl.setPaginationToken(null, backwards ? EventTimeline.BACKWARDS : EventTimeline.FORWARDS); @@ -256,7 +258,7 @@ describe("TimelinePanel", () => { describe("and reading the timeline", () => { beforeEach(async () => { await renderTimelinePanel(); - timelineSet.addLiveEvent(ev1, {}); + timelineSet.addLiveEvent(ev1, { addToState: true }); await flushPromises(); // @ts-ignore @@ -285,11 +287,11 @@ describe("TimelinePanel", () => { }); it("and forgetting the read markers, should send the stored marker again", async () => { - timelineSet.addLiveEvent(ev2, {}); + timelineSet.addLiveEvent(ev2, { addToState: true }); // Add the event to the room as well as the timeline, so we can find it when we // call findEventById in getEventReadUpTo. This is odd because in our test // setup, timelineSet is not actually the timelineSet of the room. - await room.addLiveEvents([ev2], {}); + await room.addLiveEvents([ev2], { addToState: true }); room.addEphemeralEvents([newReceipt(ev2.getId()!, userId, 222, 200)]); await timelinePanel.forgetReadMarker(); expect(client.setRoomReadMarkers).toHaveBeenCalledWith(roomId, ev2.getId()); @@ -315,7 +317,7 @@ describe("TimelinePanel", () => { it("should send a fully read marker and a private receipt", async () => { await renderTimelinePanel(); - timelineSet.addLiveEvent(ev1, {}); + timelineSet.addLiveEvent(ev1, { addToState: true }); await flushPromises(); // @ts-ignore @@ -361,7 +363,7 @@ describe("TimelinePanel", () => { it("should send receipts but no fully_read when reading the thread timeline", async () => { await renderTimelinePanel(); - timelineSet.addLiveEvent(threadEv1, {}); + timelineSet.addLiveEvent(threadEv1, { addToState: true }); await flushPromises(); // @ts-ignore @@ -871,7 +873,9 @@ describe("TimelinePanel", () => { // @ts-ignore thread.fetchEditsWhereNeeded = () => Promise.resolve(); await thread.addEvent(reply1, false, true); - await allThreads.getLiveTimeline().addEvent(thread.rootEvent!, { toStartOfTimeline: true }); + await allThreads + .getLiveTimeline() + .addEvent(thread.rootEvent!, { toStartOfTimeline: true, addToState: true }); const replyToEvent = jest.spyOn(thread, "replyToEvent", "get"); const dom = render( @@ -907,7 +911,9 @@ describe("TimelinePanel", () => { // @ts-ignore realThread.fetchEditsWhereNeeded = () => Promise.resolve(); await realThread.addEvent(reply1, true); - await allThreads.getLiveTimeline().addEvent(realThread.rootEvent!, { toStartOfTimeline: true }); + await allThreads + .getLiveTimeline() + .addEvent(realThread.rootEvent!, { toStartOfTimeline: true, addToState: true }); const replyToEvent = jest.spyOn(realThread, "replyToEvent", "get"); // @ts-ignore @@ -968,7 +974,9 @@ describe("TimelinePanel", () => { events.push(rootEvent); - events.forEach((event) => timelineSet.getLiveTimeline().addEvent(event, { toStartOfTimeline: true })); + events.forEach((event) => + timelineSet.getLiveTimeline().addEvent(event, { toStartOfTimeline: true, addToState: true }), + ); const roomMembership = mkMembership({ mship: KnownMembership.Join, @@ -988,7 +996,10 @@ describe("TimelinePanel", () => { jest.spyOn(roomState, "getMember").mockReturnValue(member); jest.spyOn(timelineSet.getLiveTimeline(), "getState").mockReturnValue(roomState); - timelineSet.addEventToTimeline(roomMembership, timelineSet.getLiveTimeline(), { toStartOfTimeline: false }); + timelineSet.addEventToTimeline(roomMembership, timelineSet.getLiveTimeline(), { + toStartOfTimeline: false, + addToState: true, + }); for (const event of events) { jest.spyOn(event, "isDecryptionFailure").mockReturnValue(true); diff --git a/test/unit-tests/components/views/context_menus/RoomGeneralContextMenu-test.tsx b/test/unit-tests/components/views/context_menus/RoomGeneralContextMenu-test.tsx index 10de3996e6..97517ff9d6 100644 --- a/test/unit-tests/components/views/context_menus/RoomGeneralContextMenu-test.tsx +++ b/test/unit-tests/components/views/context_menus/RoomGeneralContextMenu-test.tsx @@ -127,7 +127,7 @@ describe("RoomGeneralContextMenu", () => { user: "@user:id", ts: 1000, }); - room.addLiveEvents([event], {}); + room.addLiveEvents([event], { addToState: true }); const { container } = getComponent({}); diff --git a/test/unit-tests/components/views/dialogs/InviteDialog-test.tsx b/test/unit-tests/components/views/dialogs/InviteDialog-test.tsx index 62cb01b46e..7ed57a7d70 100644 --- a/test/unit-tests/components/views/dialogs/InviteDialog-test.tsx +++ b/test/unit-tests/components/views/dialogs/InviteDialog-test.tsx @@ -141,16 +141,19 @@ describe("InviteDialog", () => { jest.clearAllMocks(); room = new Room(roomId, mockClient, mockClient.getSafeUserId()); - room.addLiveEvents([ - mkMessage({ - msg: "Hello", - relatesTo: undefined, - event: true, - room: roomId, - user: mockClient.getSafeUserId(), - ts: Date.now(), - }), - ]); + room.addLiveEvents( + [ + mkMessage({ + msg: "Hello", + relatesTo: undefined, + event: true, + room: roomId, + user: mockClient.getSafeUserId(), + ts: Date.now(), + }), + ], + { addToState: true }, + ); room.currentState.setStateEvents([ mkRoomCreateEvent(bobId, roomId), mkMembership({ diff --git a/test/unit-tests/components/views/elements/Pill-test.tsx b/test/unit-tests/components/views/elements/Pill-test.tsx index 24fb2ca5dd..ee50417123 100644 --- a/test/unit-tests/components/views/elements/Pill-test.tsx +++ b/test/unit-tests/components/views/elements/Pill-test.tsx @@ -86,7 +86,7 @@ describe("", () => { room: room1Id, msg: "Room 1 Message", }); - room1.addLiveEvents([room1Message]); + room1.addLiveEvents([room1Message], { addToState: true }); room2 = new Room(room2Id, client, user1Id); room2.currentState.setStateEvents([mkRoomMemberJoinEvent(user2Id, room2Id)]); diff --git a/test/unit-tests/components/views/elements/RoomTopic-test.tsx b/test/unit-tests/components/views/elements/RoomTopic-test.tsx index dcf80a95b9..0fe833fe4e 100644 --- a/test/unit-tests/components/views/elements/RoomTopic-test.tsx +++ b/test/unit-tests/components/views/elements/RoomTopic-test.tsx @@ -41,7 +41,7 @@ describe("", () => { ts: 123, event: true, }); - room.addLiveEvents([topicEvent]); + room.addLiveEvents([topicEvent], { addToState: true }); return room; } diff --git a/test/unit-tests/components/views/rooms/NotificationBadge/UnreadNotificationBadge-test.tsx b/test/unit-tests/components/views/rooms/NotificationBadge/UnreadNotificationBadge-test.tsx index ea54dc1085..5b2dddc73a 100644 --- a/test/unit-tests/components/views/rooms/NotificationBadge/UnreadNotificationBadge-test.tsx +++ b/test/unit-tests/components/views/rooms/NotificationBadge/UnreadNotificationBadge-test.tsx @@ -165,7 +165,7 @@ describe("UnreadNotificationBadge", () => { }, ts: 5, }); - room.addLiveEvents([event]); + room.addLiveEvents([event], { addToState: true }); const { container } = render(getComponent(THREAD_ID)); expect(container.querySelector(".mx_NotificationBadge_dot")).toBeTruthy(); diff --git a/test/unit-tests/components/views/rooms/RoomHeader-test.tsx b/test/unit-tests/components/views/rooms/RoomHeader-test.tsx index a7e556e452..3cb4b159cd 100644 --- a/test/unit-tests/components/views/rooms/RoomHeader-test.tsx +++ b/test/unit-tests/components/views/rooms/RoomHeader-test.tsx @@ -579,7 +579,7 @@ describe("RoomHeader", () => { state_key: "", room_id: room.roomId, }); - room.addLiveEvents([joinRuleEvent]); + room.addLiveEvents([joinRuleEvent], { addToState: true }); render(, getWrapper()); diff --git a/test/unit-tests/components/views/settings/Notifications-test.tsx b/test/unit-tests/components/views/settings/Notifications-test.tsx index 69b45135cb..e3d9716901 100644 --- a/test/unit-tests/components/views/settings/Notifications-test.tsx +++ b/test/unit-tests/components/views/settings/Notifications-test.tsx @@ -915,7 +915,7 @@ describe("", () => { user: "@alice:example.org", ts: 1, }); - await room.addLiveEvents([message]); + await room.addLiveEvents([message], { addToState: true }); const { container } = await getComponentAndWait(); const clearNotificationEl = getByTestId(container, "clear-notifications"); diff --git a/test/unit-tests/components/views/settings/notifications/Notifications2-test.tsx b/test/unit-tests/components/views/settings/notifications/Notifications2-test.tsx index 029777c153..2507aa173f 100644 --- a/test/unit-tests/components/views/settings/notifications/Notifications2-test.tsx +++ b/test/unit-tests/components/views/settings/notifications/Notifications2-test.tsx @@ -716,7 +716,7 @@ describe("", () => { user: "@alice:example.org", ts: 1, }); - room.addLiveEvents([message]); + room.addLiveEvents([message], { addToState: true }); room.setUnreadNotificationCount(NotificationCountType.Total, 1); const user = userEvent.setup(); diff --git a/test/unit-tests/events/EventTileFactory-test.ts b/test/unit-tests/events/EventTileFactory-test.ts index 9c8f7718af..7044a883d0 100644 --- a/test/unit-tests/events/EventTileFactory-test.ts +++ b/test/unit-tests/events/EventTileFactory-test.ts @@ -88,7 +88,7 @@ describe("pickFactory", () => { client.getUserId()!, client.deviceId!, ); - room.addLiveEvents([voiceBroadcastStartedEvent]); + room.addLiveEvents([voiceBroadcastStartedEvent], { addToState: true }); voiceBroadcastStoppedEvent = mkVoiceBroadcastInfoStateEvent( roomId, VoiceBroadcastInfoState.Stopped, diff --git a/test/unit-tests/models/Call-test.ts b/test/unit-tests/models/Call-test.ts index 40e929fb4a..316adbbea9 100644 --- a/test/unit-tests/models/Call-test.ts +++ b/test/unit-tests/models/Call-test.ts @@ -119,7 +119,7 @@ const setUpClientRoomAndStores = (): { skey: stateKey, content: content as IContent, }); - room.addLiveEvents([event]); + room.addLiveEvents([event], { addToState: true }); return { event_id: event.getId()! }; }); diff --git a/test/unit-tests/stores/MemberListStore-test.ts b/test/unit-tests/stores/MemberListStore-test.ts index 889a9d3505..184576f317 100644 --- a/test/unit-tests/stores/MemberListStore-test.ts +++ b/test/unit-tests/stores/MemberListStore-test.ts @@ -202,6 +202,7 @@ describe("MemberListStore", () => { function addEventToRoom(room: Room, ev: MatrixEvent) { room.getLiveTimeline().addEvent(ev, { toStartOfTimeline: false, + addToState: true, }); } diff --git a/test/unit-tests/stores/RoomViewStore-test.ts b/test/unit-tests/stores/RoomViewStore-test.ts index 7d397397dc..f7ed1dfbcd 100644 --- a/test/unit-tests/stores/RoomViewStore-test.ts +++ b/test/unit-tests/stores/RoomViewStore-test.ts @@ -397,7 +397,7 @@ describe("RoomViewStore", function () { mockClient.getSafeUserId(), "ABC123", ); - room2.addLiveEvents([broadcastEvent]); + room2.addLiveEvents([broadcastEvent], { addToState: true }); stores.voiceBroadcastPlaybacksStore.getByInfoEvent(broadcastEvent, mockClient); dis.dispatch({ action: Action.ViewRoom, room_id: roomId2 }); diff --git a/test/unit-tests/stores/room-list/MessagePreviewStore-test.ts b/test/unit-tests/stores/room-list/MessagePreviewStore-test.ts index 75013bd4e1..861b6dcd11 100644 --- a/test/unit-tests/stores/room-list/MessagePreviewStore-test.ts +++ b/test/unit-tests/stores/room-list/MessagePreviewStore-test.ts @@ -35,7 +35,7 @@ describe("MessagePreviewStore", () => { event: MatrixEvent, fireAction = true, ): Promise { - room.addLiveEvents([event]); + room.addLiveEvents([event], { addToState: true }); if (fireAction) { // @ts-ignore private access await store.onAction({ diff --git a/test/unit-tests/stores/room-list/algorithms/RecentAlgorithm-test.ts b/test/unit-tests/stores/room-list/algorithms/RecentAlgorithm-test.ts index 18a073b632..e0e06bbaf7 100644 --- a/test/unit-tests/stores/room-list/algorithms/RecentAlgorithm-test.ts +++ b/test/unit-tests/stores/room-list/algorithms/RecentAlgorithm-test.ts @@ -47,11 +47,11 @@ describe("RecentAlgorithm", () => { room.getMyMembership = () => KnownMembership.Join; - room.addLiveEvents([event1]); + room.addLiveEvents([event1], { addToState: true }); expect(algorithm.getLastTs(room, "@jane:matrix.org")).toBe(5); expect(algorithm.getLastTs(room, "@john:matrix.org")).toBe(5); - room.addLiveEvents([event2]); + room.addLiveEvents([event2], { addToState: true }); expect(algorithm.getLastTs(room, "@jane:matrix.org")).toBe(10); expect(algorithm.getLastTs(room, "@john:matrix.org")).toBe(10); @@ -94,8 +94,8 @@ describe("RecentAlgorithm", () => { event: true, }); - room1.addLiveEvents([evt]); - room2.addLiveEvents([evt2]); + room1.addLiveEvents([evt], { addToState: true }); + room2.addLiveEvents([evt2], { addToState: true }); expect(algorithm.sortRooms([room2, room1], DefaultTagID.Untagged)).toEqual([room1, room2]); }); @@ -115,7 +115,7 @@ describe("RecentAlgorithm", () => { event: true, }); - room1.addLiveEvents([evt]); + room1.addLiveEvents([evt], { addToState: true }); expect(algorithm.sortRooms([room2, room1], DefaultTagID.Untagged)).toEqual([room2, room1]); @@ -127,7 +127,7 @@ describe("RecentAlgorithm", () => { ts: 12, }); - room1.addLiveEvents(events); + room1.addLiveEvents(events, { addToState: true }); }); it("orders rooms based on thread replies too", () => { @@ -145,7 +145,7 @@ describe("RecentAlgorithm", () => { ts: 12, length: 5, }); - room1.addLiveEvents(events1); + room1.addLiveEvents(events1, { addToState: true }); const { events: events2 } = mkThread({ room: room2, @@ -155,7 +155,7 @@ describe("RecentAlgorithm", () => { ts: 14, length: 10, }); - room2.addLiveEvents(events2); + room2.addLiveEvents(events2, { addToState: true }); expect(algorithm.sortRooms([room1, room2], DefaultTagID.Untagged)).toEqual([room2, room1]); @@ -169,7 +169,7 @@ describe("RecentAlgorithm", () => { // replies are 1ms after each other ts: 50, }); - room1.addLiveEvents([threadReply]); + room1.addLiveEvents([threadReply], { addToState: true }); expect(algorithm.sortRooms([room1, room2], DefaultTagID.Untagged)).toEqual([room1, room2]); }); diff --git a/test/unit-tests/stores/room-list/previews/ReactionEventPreview-test.ts b/test/unit-tests/stores/room-list/previews/ReactionEventPreview-test.ts index b3facccb06..7a7ce9e2b3 100644 --- a/test/unit-tests/stores/room-list/previews/ReactionEventPreview-test.ts +++ b/test/unit-tests/stores/room-list/previews/ReactionEventPreview-test.ts @@ -70,7 +70,7 @@ describe("ReactionEventPreview", () => { room: roomId, }); - room.getUnfilteredTimelineSet().addLiveEvent(message, {}); + room.getUnfilteredTimelineSet().addLiveEvent(message, { addToState: true }); const event = mkEvent({ event: true, @@ -107,7 +107,7 @@ describe("ReactionEventPreview", () => { room: roomId, }); - room.getUnfilteredTimelineSet().addLiveEvent(message, {}); + room.getUnfilteredTimelineSet().addLiveEvent(message, { addToState: true }); const event = mkEvent({ event: true, diff --git a/test/unit-tests/useTopic-test.tsx b/test/unit-tests/useTopic-test.tsx index cbef9dba60..81afaae985 100644 --- a/test/unit-tests/useTopic-test.tsx +++ b/test/unit-tests/useTopic-test.tsx @@ -29,7 +29,7 @@ describe("useTopic", () => { event: true, }); - room.addLiveEvents([topic]); + room.addLiveEvents([topic], { addToState: true }); function RoomTopic() { const topic = useTopic(room); @@ -52,7 +52,7 @@ describe("useTopic", () => { }); act(() => { - room.addLiveEvents([updatedTopic]); + room.addLiveEvents([updatedTopic], { addToState: true }); }); expect(screen.queryByText("New topic")).toBeInTheDocument(); diff --git a/test/unit-tests/utils/exportUtils/HTMLExport-test.ts b/test/unit-tests/utils/exportUtils/HTMLExport-test.ts index 0fc96e4db7..d169b55a7c 100644 --- a/test/unit-tests/utils/exportUtils/HTMLExport-test.ts +++ b/test/unit-tests/utils/exportUtils/HTMLExport-test.ts @@ -593,18 +593,21 @@ describe("HTMLExport", () => { it("should not make /messages requests when exporting 'Current Timeline'", async () => { client.createMessagesRequest.mockRejectedValue(new Error("Should never be called")); - room.addLiveEvents([ - new MatrixEvent({ - event_id: `$eventId`, - type: EventType.RoomMessage, - sender: client.getSafeUserId(), - origin_server_ts: 123456789, - content: { - msgtype: "m.text", - body: `testing testing`, - }, - }), - ]); + room.addLiveEvents( + [ + new MatrixEvent({ + event_id: `$eventId`, + type: EventType.RoomMessage, + sender: client.getSafeUserId(), + origin_server_ts: 123456789, + content: { + msgtype: "m.text", + body: `testing testing`, + }, + }), + ], + { addToState: true }, + ); const exporter = new HTMLExporter( room, diff --git a/test/unit-tests/utils/notifications-test.ts b/test/unit-tests/utils/notifications-test.ts index 67948ed217..68553de166 100644 --- a/test/unit-tests/utils/notifications-test.ts +++ b/test/unit-tests/utils/notifications-test.ts @@ -121,7 +121,7 @@ describe("notifications", () => { user: USER_ID, msg: "Hello", }); - room.addLiveEvents([message]); + room.addLiveEvents([message], { addToState: true }); sendReadReceiptSpy = jest.spyOn(client, "sendReadReceipt").mockResolvedValue({}); jest.spyOn(client, "getRooms").mockReturnValue([room]); jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => { @@ -187,7 +187,7 @@ describe("notifications", () => { user: USER_ID, ts: 1, }); - room.addLiveEvents([message]); + room.addLiveEvents([message], { addToState: true }); room.setUnreadNotificationCount(NotificationCountType.Total, 1); await clearAllNotifications(client); @@ -202,7 +202,7 @@ describe("notifications", () => { user: USER_ID, ts: 1, }); - room.addLiveEvents([message]); + room.addLiveEvents([message], { addToState: true }); room.setUnreadNotificationCount(NotificationCountType.Total, 1); jest.spyOn(SettingsStore, "getValue").mockReset().mockReturnValue(false); diff --git a/test/unit-tests/voice-broadcast/components/VoiceBroadcastBody-test.tsx b/test/unit-tests/voice-broadcast/components/VoiceBroadcastBody-test.tsx index bf55c45b68..fd416de8ce 100644 --- a/test/unit-tests/voice-broadcast/components/VoiceBroadcastBody-test.tsx +++ b/test/unit-tests/voice-broadcast/components/VoiceBroadcastBody-test.tsx @@ -85,7 +85,7 @@ describe("VoiceBroadcastBody", () => { deviceId, infoEvent, ); - room.addEventsToTimeline([infoEvent], true, room.getLiveTimeline()); + room.addEventsToTimeline([infoEvent], true, true, room.getLiveTimeline()); testRecording = new VoiceBroadcastRecording(infoEvent, client); testPlayback = new VoiceBroadcastPlayback(infoEvent, client, new VoiceBroadcastRecordingsStore()); mocked(VoiceBroadcastRecordingBody).mockImplementation(({ recording }): ReactElement | null => { @@ -127,7 +127,7 @@ describe("VoiceBroadcastBody", () => { describe("when there is a stopped voice broadcast", () => { beforeEach(() => { - room.addEventsToTimeline([stoppedEvent], true, room.getLiveTimeline()); + room.addEventsToTimeline([stoppedEvent], true, true, room.getLiveTimeline()); renderVoiceBroadcast(); }); @@ -148,7 +148,7 @@ describe("VoiceBroadcastBody", () => { describe("and the recordings ends", () => { beforeEach(() => { act(() => { - room.addEventsToTimeline([stoppedEvent], true, room.getLiveTimeline()); + room.addEventsToTimeline([stoppedEvent], true, true, room.getLiveTimeline()); }); }); diff --git a/test/unit-tests/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx b/test/unit-tests/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx index c967189271..9ce24e5921 100644 --- a/test/unit-tests/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx +++ b/test/unit-tests/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx @@ -243,7 +243,7 @@ describe("VoiceBroadcastPlayback", () => { beforeEach(async () => { infoEvent = mkInfoEvent(VoiceBroadcastInfoState.Resumed); createChunkEvents(); - room.addLiveEvents([infoEvent]); + room.addLiveEvents([infoEvent], { addToState: true }); playback = await mkPlayback(); }); @@ -331,7 +331,7 @@ describe("VoiceBroadcastPlayback", () => { infoEvent = mkInfoEvent(VoiceBroadcastInfoState.Resumed); createChunkEvents(); setUpChunkEvents([chunk2Event, chunk1Event]); - room.addLiveEvents([infoEvent, chunk1Event, chunk2Event]); + room.addLiveEvents([infoEvent, chunk1Event, chunk2Event], { addToState: true }); room.relations.aggregateChildEvent(chunk2Event); room.relations.aggregateChildEvent(chunk1Event); playback = await mkPlayback(); @@ -372,7 +372,7 @@ describe("VoiceBroadcastPlayback", () => { describe("and an event with the same transaction Id occurs", () => { beforeEach(() => { - room.addLiveEvents([chunk2BEvent]); + room.addLiveEvents([chunk2BEvent], { addToState: true }); room.relations.aggregateChildEvent(chunk2BEvent); }); @@ -404,7 +404,7 @@ describe("VoiceBroadcastPlayback", () => { infoEvent, 2, ); - room.addLiveEvents([stoppedEvent]); + room.addLiveEvents([stoppedEvent], { addToState: true }); room.relations.aggregateChildEvent(stoppedEvent); chunk2Playback.emit(PlaybackState.Stopped); }); @@ -426,7 +426,7 @@ describe("VoiceBroadcastPlayback", () => { infoEvent, 3, ); - room.addLiveEvents([stoppedEvent]); + room.addLiveEvents([stoppedEvent], { addToState: true }); room.relations.aggregateChildEvent(stoppedEvent); chunk2Playback.emit(PlaybackState.Stopped); }); @@ -435,7 +435,7 @@ describe("VoiceBroadcastPlayback", () => { describe("and the next chunk arrives", () => { beforeEach(() => { - room.addLiveEvents([chunk3Event]); + room.addLiveEvents([chunk3Event], { addToState: true }); room.relations.aggregateChildEvent(chunk3Event); }); @@ -521,7 +521,7 @@ describe("VoiceBroadcastPlayback", () => { createChunkEvents(); // use delayed first chunk here to simulate loading time setUpChunkEvents([chunk2Event, deplayedChunk1Event, chunk3Event]); - room.addLiveEvents([infoEvent, deplayedChunk1Event, chunk2Event, chunk3Event]); + room.addLiveEvents([infoEvent, deplayedChunk1Event, chunk2Event, chunk3Event], { addToState: true }); playback = await mkPlayback(true); }); diff --git a/test/unit-tests/voice-broadcast/utils/hasRoomLiveVoiceBroadcast-test.ts b/test/unit-tests/voice-broadcast/utils/hasRoomLiveVoiceBroadcast-test.ts index 589e1c46a7..37fbf0c277 100644 --- a/test/unit-tests/voice-broadcast/utils/hasRoomLiveVoiceBroadcast-test.ts +++ b/test/unit-tests/voice-broadcast/utils/hasRoomLiveVoiceBroadcast-test.ts @@ -32,7 +32,7 @@ describe("hasRoomLiveVoiceBroadcast", () => { startedEvent?: MatrixEvent, ): MatrixEvent => { const infoEvent = mkVoiceBroadcastInfoStateEvent(room.roomId, state, userId, deviceId, startedEvent); - room.addLiveEvents([infoEvent]); + room.addLiveEvents([infoEvent], { addToState: true }); room.currentState.setStateEvents([infoEvent]); room.relations.aggregateChildEvent(infoEvent); return infoEvent; diff --git a/test/unit-tests/voice-broadcast/utils/isRelatedToVoiceBroadcast-test.ts b/test/unit-tests/voice-broadcast/utils/isRelatedToVoiceBroadcast-test.ts index 17160b8b2b..eae78df109 100644 --- a/test/unit-tests/voice-broadcast/utils/isRelatedToVoiceBroadcast-test.ts +++ b/test/unit-tests/voice-broadcast/utils/isRelatedToVoiceBroadcast-test.ts @@ -31,7 +31,7 @@ const mkRelatedEvent = ( }, user: client.getSafeUserId(), }); - room.addLiveEvents([event]); + room.addLiveEvents([event], { addToState: true }); return event; }; @@ -65,7 +65,7 @@ describe("isRelatedToVoiceBroadcast", () => { user: client.getSafeUserId(), }); - room.addLiveEvents([broadcastEvent, nonBroadcastEvent]); + room.addLiveEvents([broadcastEvent, nonBroadcastEvent], { addToState: true }); }); it("should return true if related (reference) to a broadcast event", () => { diff --git a/test/unit-tests/voice-broadcast/utils/retrieveStartedInfoEvent-test.ts b/test/unit-tests/voice-broadcast/utils/retrieveStartedInfoEvent-test.ts index 9bac7aed3e..70316f3b29 100644 --- a/test/unit-tests/voice-broadcast/utils/retrieveStartedInfoEvent-test.ts +++ b/test/unit-tests/voice-broadcast/utils/retrieveStartedInfoEvent-test.ts @@ -67,7 +67,7 @@ describe("retrieveStartedInfoEvent", () => { it("when the room contains the event, it should return it", async () => { const startEvent = mkStartEvent(); const stopEvent = mkStopEvent(startEvent); - room.addLiveEvents([startEvent]); + room.addLiveEvents([startEvent], { addToState: true }); expect(await retrieveStartedInfoEvent(stopEvent, client)).toBe(startEvent); }); From 0b636aec4bcf4991354c23d4a32986f3fc192e16 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 8 Nov 2024 16:41:57 +0000 Subject: [PATCH 2/2] Improve coverage Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../components/structures/FilePanel-test.tsx | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/test/unit-tests/components/structures/FilePanel-test.tsx b/test/unit-tests/components/structures/FilePanel-test.tsx index 1dce220682..25bdd99676 100644 --- a/test/unit-tests/components/structures/FilePanel-test.tsx +++ b/test/unit-tests/components/structures/FilePanel-test.tsx @@ -7,13 +7,13 @@ Please see LICENSE files in the repository root for full details. */ import React from "react"; -import { EventTimelineSet, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix"; +import { EventTimelineSet, PendingEventOrdering, Room, RoomEvent } from "matrix-js-sdk/src/matrix"; import { screen, render, waitFor } from "jest-matrix-react"; import { mocked } from "jest-mock"; import FilePanel from "../../../../src/components/structures/FilePanel"; import ResizeNotifier from "../../../../src/utils/ResizeNotifier"; -import { stubClient } from "../../../test-utils"; +import { mkEvent, stubClient } from "../../../test-utils"; import { MatrixClientPeg } from "../../../../src/MatrixClientPeg"; jest.mock("matrix-js-sdk/src/matrix", () => ({ @@ -47,4 +47,43 @@ describe("FilePanel", () => { }); expect(asFragment()).toMatchSnapshot(); }); + + describe("addEncryptedLiveEvent", () => { + it("should add file msgtype event to filtered timelineSet", async () => { + const cli = MatrixClientPeg.safeGet(); + const room = new Room("!room:server", cli, cli.getSafeUserId(), { + pendingEventOrdering: PendingEventOrdering.Detached, + }); + cli.reEmitter.reEmit(room, [RoomEvent.Timeline]); + const timelineSet = new EventTimelineSet(room); + room.getOrCreateFilteredTimelineSet = jest.fn().mockReturnValue(timelineSet); + mocked(cli.getRoom).mockReturnValue(room); + + let filePanel: FilePanel | null; + render( + (filePanel = ref)} + />, + ); + await screen.findByText("No files visible in this room"); + + const event = mkEvent({ + type: "m.room.message", + user: cli.getSafeUserId(), + room: room.roomId, + content: { + body: "hello", + url: "mxc://matrix.org/1234", + msgtype: "m.file", + }, + event: true, + }); + filePanel!.addEncryptedLiveEvent(event); + + expect(timelineSet.getLiveTimeline().getEvents()).toContain(event); + }); + }); });