From 87b9c95e86aca48ea64444dbeffb8758fa494b6d Mon Sep 17 00:00:00 2001 From: Janne Mareike Koschinski Date: Thu, 19 Jan 2023 16:20:39 +0100 Subject: [PATCH 1/2] Allow thread panel to be closed after being opened from notification --- src/components/structures/ThreadView.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/structures/ThreadView.tsx b/src/components/structures/ThreadView.tsx index 833ce4de67b..8d553b55497 100644 --- a/src/components/structures/ThreadView.tsx +++ b/src/components/structures/ThreadView.tsx @@ -1,5 +1,5 @@ /* -Copyright 2021 - 2022 The Matrix.org Foundation C.I.C. +Copyright 2021 - 2023 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -123,7 +123,7 @@ export default class ThreadView extends React.Component { SettingsStore.unwatchSetting(this.layoutWatcherRef); const hasRoomChanged = SdkContextClass.instance.roomViewStore.getRoomId() !== roomId; - if (this.props.isInitialEventHighlighted && !hasRoomChanged) { + if (this.props.initialEvent && !hasRoomChanged) { dis.dispatch({ action: Action.ViewRoom, room_id: this.props.room.roomId, From e35c1f662c5e6e44a842f59dbf1b0f0ca6fef4a2 Mon Sep 17 00:00:00 2001 From: Janne Mareike Koschinski Date: Mon, 23 Jan 2023 13:59:08 +0100 Subject: [PATCH 2/2] Add test to ensure the behavior is correct --- .../components/structures/ThreadView-test.tsx | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/test/components/structures/ThreadView-test.tsx b/test/components/structures/ThreadView-test.tsx index 16113426e17..c578121e461 100644 --- a/test/components/structures/ThreadView-test.tsx +++ b/test/components/structures/ThreadView-test.tsx @@ -1,5 +1,5 @@ /* -Copyright 2022 The Matrix.org Foundation C.I.C. +Copyright 2022-2023 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -29,6 +29,8 @@ import ThreadView from "../../../src/components/structures/ThreadView"; import MatrixClientContext from "../../../src/contexts/MatrixClientContext"; import RoomContext from "../../../src/contexts/RoomContext"; import { SdkContextClass } from "../../../src/contexts/SDKContext"; +import { Action } from "../../../src/dispatcher/actions"; +import dispatcher from "../../../src/dispatcher/dispatcher"; import { MatrixClientPeg } from "../../../src/MatrixClientPeg"; import DMRoomMap from "../../../src/utils/DMRoomMap"; import ResizeNotifier from "../../../src/utils/ResizeNotifier"; @@ -47,7 +49,7 @@ describe("ThreadView", () => { let changeEvent: (event: MatrixEvent) => void; - function TestThreadView() { + function TestThreadView({ initialEvent }: { initialEvent?: MatrixEvent }) { const [event, setEvent] = useState(rootEvent); changeEvent = setEvent; @@ -58,15 +60,21 @@ describe("ThreadView", () => { canSendMessages: true, })} > - + , ); } - async function getComponent(): Promise { - const renderResult = render(); + async function getComponent(initialEvent?: MatrixEvent): Promise { + const renderResult = render(); await waitFor(() => { expect(() => getByTestId(renderResult.container, "spinner")).toThrow(); @@ -171,4 +179,17 @@ describe("ThreadView", () => { unmount(); await waitFor(() => expect(SdkContextClass.instance.roomViewStore.getThreadId()).toBeNull()); }); + + it("clears highlight message in the room view store", async () => { + jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(room.roomId); + const mock = jest.spyOn(dispatcher, "dispatch"); + const { unmount } = await getComponent(rootEvent); + mock.mockClear(); + unmount(); + expect(mock).toHaveBeenCalledWith({ + action: Action.ViewRoom, + room_id: room.roomId, + metricsTrigger: undefined, + }); + }); });