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

Commit 0bbb9e8

Browse files
author
Kerry
authored
Right panel: view third party invite info without clearing history (#11934)
* add View3pidInvite to actions enum, replace uses * extract out action handler * push card instead, test * comment
1 parent fbd64d3 commit 0bbb9e8

File tree

7 files changed

+124
-10
lines changed

7 files changed

+124
-10
lines changed

src/components/structures/RoomView.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ import { isNotUndefined } from "../../Typeguards";
131131
import { CancelAskToJoinPayload } from "../../dispatcher/payloads/CancelAskToJoinPayload";
132132
import { SubmitAskToJoinPayload } from "../../dispatcher/payloads/SubmitAskToJoinPayload";
133133
import RightPanelStore from "../../stores/right-panel/RightPanelStore";
134+
import { onView3pidInvite } from "../../stores/right-panel/action-handlers";
134135

135136
const DEBUG = false;
136137
const PREVENT_MULTIPLE_JITSI_WITHIN = 30_000;
@@ -1272,14 +1273,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
12721273
RightPanelStore.instance.showOrHidePanel(RightPanelPhases.RoomMemberList);
12731274
}
12741275
break;
1275-
case "view_3pid_invite":
1276-
if (payload.event) {
1277-
RightPanelStore.instance.showOrHidePanel(RightPanelPhases.Room3pidMemberInfo, {
1278-
memberInfoEvent: payload.event,
1279-
});
1280-
} else {
1281-
RightPanelStore.instance.showOrHidePanel(RightPanelPhases.RoomMemberList);
1282-
}
1276+
case Action.View3pidInvite:
1277+
onView3pidInvite(payload, RightPanelStore.instance);
12831278
break;
12841279
}
12851280
};

src/components/views/rooms/MemberList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import PosthogTrackers from "../../../PosthogTrackers";
5555
import { SDKContext } from "../../../contexts/SDKContext";
5656
import { canInviteTo } from "../../../utils/room/canInviteTo";
5757
import { inviteToRoom } from "../../../utils/room/inviteToRoom";
58+
import { Action } from "../../../dispatcher/actions";
5859

5960
const INITIAL_LOAD_NUM_MEMBERS = 30;
6061
const INITIAL_LOAD_NUM_INVITED = 5;
@@ -275,7 +276,7 @@ export default class MemberList extends React.Component<IProps, IState> {
275276

276277
private onPending3pidInviteClick = (inviteEvent: MatrixEvent): void => {
277278
dis.dispatch({
278-
action: "view_3pid_invite",
279+
action: Action.View3pidInvite,
279280
event: inviteEvent,
280281
});
281282
};

src/components/views/rooms/ThirdPartyMemberInfo.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import RoomAvatar from "../avatars/RoomAvatar";
2727
import RoomName from "../elements/RoomName";
2828
import ErrorDialog from "../dialogs/ErrorDialog";
2929
import AccessibleButton from "../elements/AccessibleButton";
30+
import { Action } from "../../../dispatcher/actions";
3031

3132
interface IProps {
3233
event: MatrixEvent;
@@ -91,7 +92,7 @@ export default class ThirdPartyMemberInfo extends React.Component<IProps, IState
9192

9293
public onCancel = (): void => {
9394
dis.dispatch({
94-
action: "view_3pid_invite",
95+
action: Action.View3pidInvite,
9596
event: null,
9697
});
9798
};

src/dispatcher/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,9 @@ export enum Action {
376376
* Fired when the room loaded.
377377
*/
378378
RoomLoaded = "room_loaded",
379+
380+
/**
381+
* Opens right panel with 3pid invite information
382+
*/
383+
View3pidInvite = "view_3pid_invite",
379384
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2023 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { ActionPayload } from "../../../dispatcher/payloads";
18+
import RightPanelStore from "../RightPanelStore";
19+
import { RightPanelPhases } from "../RightPanelStorePhases";
20+
21+
/**
22+
* Handle an Action.View3pidInvite action.
23+
* Where payload has an event, open the right panel with 3pid room member info without clearing right panel history.
24+
* Otherwise, 'close' the 3pid member info by displaying the room member list in the right panel.
25+
* @param payload
26+
* @param rightPanelStore store instance
27+
*/
28+
export const onView3pidInvite = (payload: ActionPayload, rightPanelStore: RightPanelStore): void => {
29+
if (payload.event) {
30+
rightPanelStore.pushCard({
31+
phase: RightPanelPhases.Room3pidMemberInfo,
32+
state: { memberInfoEvent: payload.event },
33+
});
34+
} else {
35+
rightPanelStore.showOrHidePanel(RightPanelPhases.RoomMemberList);
36+
}
37+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright 2023 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
export * from "./View3pidInvite";
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2023 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { MockedObject } from "jest-mock";
18+
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
19+
20+
import { Action } from "../../../../src/dispatcher/actions";
21+
import { onView3pidInvite } from "../../../../src/stores/right-panel/action-handlers";
22+
import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore";
23+
import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases";
24+
25+
describe("onView3pidInvite()", () => {
26+
let rightPanelStore!: MockedObject<RightPanelStore>;
27+
28+
beforeEach(() => {
29+
rightPanelStore = {
30+
pushCard: jest.fn(),
31+
showOrHidePanel: jest.fn(),
32+
} as unknown as MockedObject<RightPanelStore>;
33+
});
34+
35+
it("should display room member list when payload has a falsy event", () => {
36+
const payload = {
37+
action: Action.View3pidInvite,
38+
};
39+
onView3pidInvite(payload, rightPanelStore);
40+
41+
expect(rightPanelStore.showOrHidePanel).toHaveBeenCalledWith(RightPanelPhases.RoomMemberList);
42+
expect(rightPanelStore.pushCard).not.toHaveBeenCalled();
43+
});
44+
45+
it("should push a 3pid member card on the right panel stack when payload has an event", () => {
46+
const payload = {
47+
action: Action.View3pidInvite,
48+
event: new MatrixEvent({ type: EventType.RoomThirdPartyInvite }),
49+
};
50+
onView3pidInvite(payload, rightPanelStore);
51+
52+
expect(rightPanelStore.showOrHidePanel).not.toHaveBeenCalled();
53+
expect(rightPanelStore.pushCard).toHaveBeenCalledWith({
54+
phase: RightPanelPhases.Room3pidMemberInfo,
55+
state: { memberInfoEvent: payload.event },
56+
});
57+
});
58+
});

0 commit comments

Comments
 (0)