Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit a0a419a

Browse files
authored
Allow thread panel to be closed after being opened from notification (#9937)
* Allow thread panel to be closed after being opened from notification * Add test to ensure the behavior is correct
1 parent 056fec8 commit a0a419a

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/components/structures/ThreadView.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2021 - 2022 The Matrix.org Foundation C.I.C.
2+
Copyright 2021 - 2023 The Matrix.org Foundation C.I.C.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -123,7 +123,7 @@ export default class ThreadView extends React.Component<IProps, IState> {
123123
SettingsStore.unwatchSetting(this.layoutWatcherRef);
124124

125125
const hasRoomChanged = SdkContextClass.instance.roomViewStore.getRoomId() !== roomId;
126-
if (this.props.isInitialEventHighlighted && !hasRoomChanged) {
126+
if (this.props.initialEvent && !hasRoomChanged) {
127127
dis.dispatch<ViewRoomPayload>({
128128
action: Action.ViewRoom,
129129
room_id: this.props.room.roomId,

test/components/structures/ThreadView-test.tsx

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 The Matrix.org Foundation C.I.C.
2+
Copyright 2022-2023 The Matrix.org Foundation C.I.C.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -29,6 +29,8 @@ import ThreadView from "../../../src/components/structures/ThreadView";
2929
import MatrixClientContext from "../../../src/contexts/MatrixClientContext";
3030
import RoomContext from "../../../src/contexts/RoomContext";
3131
import { SdkContextClass } from "../../../src/contexts/SDKContext";
32+
import { Action } from "../../../src/dispatcher/actions";
33+
import dispatcher from "../../../src/dispatcher/dispatcher";
3234
import { MatrixClientPeg } from "../../../src/MatrixClientPeg";
3335
import DMRoomMap from "../../../src/utils/DMRoomMap";
3436
import ResizeNotifier from "../../../src/utils/ResizeNotifier";
@@ -47,7 +49,7 @@ describe("ThreadView", () => {
4749

4850
let changeEvent: (event: MatrixEvent) => void;
4951

50-
function TestThreadView() {
52+
function TestThreadView({ initialEvent }: { initialEvent?: MatrixEvent }) {
5153
const [event, setEvent] = useState(rootEvent);
5254
changeEvent = setEvent;
5355

@@ -58,15 +60,21 @@ describe("ThreadView", () => {
5860
canSendMessages: true,
5961
})}
6062
>
61-
<ThreadView room={room} onClose={jest.fn()} mxEvent={event} resizeNotifier={new ResizeNotifier()} />
63+
<ThreadView
64+
room={room}
65+
onClose={jest.fn()}
66+
mxEvent={event}
67+
initialEvent={initialEvent}
68+
resizeNotifier={new ResizeNotifier()}
69+
/>
6270
</RoomContext.Provider>
6371
,
6472
</MatrixClientContext.Provider>
6573
);
6674
}
6775

68-
async function getComponent(): Promise<RenderResult> {
69-
const renderResult = render(<TestThreadView />);
76+
async function getComponent(initialEvent?: MatrixEvent): Promise<RenderResult> {
77+
const renderResult = render(<TestThreadView initialEvent={initialEvent} />);
7078

7179
await waitFor(() => {
7280
expect(() => getByTestId(renderResult.container, "spinner")).toThrow();
@@ -171,4 +179,17 @@ describe("ThreadView", () => {
171179
unmount();
172180
await waitFor(() => expect(SdkContextClass.instance.roomViewStore.getThreadId()).toBeNull());
173181
});
182+
183+
it("clears highlight message in the room view store", async () => {
184+
jest.spyOn(SdkContextClass.instance.roomViewStore, "getRoomId").mockReturnValue(room.roomId);
185+
const mock = jest.spyOn(dispatcher, "dispatch");
186+
const { unmount } = await getComponent(rootEvent);
187+
mock.mockClear();
188+
unmount();
189+
expect(mock).toHaveBeenCalledWith({
190+
action: Action.ViewRoom,
191+
room_id: room.roomId,
192+
metricsTrigger: undefined,
193+
});
194+
});
174195
});

0 commit comments

Comments
 (0)