From 83b941fc66535edf0321b066aeadd0c6c118461d Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 27 Nov 2023 15:01:44 +1300 Subject: [PATCH 1/4] add View3pidInvite to actions enum, replace uses --- src/components/structures/RoomView.tsx | 2 +- src/components/views/rooms/MemberList.tsx | 3 ++- src/components/views/rooms/ThirdPartyMemberInfo.tsx | 3 ++- src/dispatcher/actions.ts | 5 +++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 9887e9cc60d..be4744c46f5 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -1272,7 +1272,7 @@ export class RoomView extends React.Component { RightPanelStore.instance.showOrHidePanel(RightPanelPhases.RoomMemberList); } break; - case "view_3pid_invite": + case Action.View3pidInvite: if (payload.event) { RightPanelStore.instance.showOrHidePanel(RightPanelPhases.Room3pidMemberInfo, { memberInfoEvent: payload.event, diff --git a/src/components/views/rooms/MemberList.tsx b/src/components/views/rooms/MemberList.tsx index 582d3293109..64c3400bb98 100644 --- a/src/components/views/rooms/MemberList.tsx +++ b/src/components/views/rooms/MemberList.tsx @@ -55,6 +55,7 @@ import PosthogTrackers from "../../../PosthogTrackers"; import { SDKContext } from "../../../contexts/SDKContext"; import { canInviteTo } from "../../../utils/room/canInviteTo"; import { inviteToRoom } from "../../../utils/room/inviteToRoom"; +import { Action } from "../../../dispatcher/actions"; const INITIAL_LOAD_NUM_MEMBERS = 30; const INITIAL_LOAD_NUM_INVITED = 5; @@ -275,7 +276,7 @@ export default class MemberList extends React.Component { private onPending3pidInviteClick = (inviteEvent: MatrixEvent): void => { dis.dispatch({ - action: "view_3pid_invite", + action: Action.View3pidInvite, event: inviteEvent, }); }; diff --git a/src/components/views/rooms/ThirdPartyMemberInfo.tsx b/src/components/views/rooms/ThirdPartyMemberInfo.tsx index 46ecea95831..c7ccf48e85c 100644 --- a/src/components/views/rooms/ThirdPartyMemberInfo.tsx +++ b/src/components/views/rooms/ThirdPartyMemberInfo.tsx @@ -27,6 +27,7 @@ import RoomAvatar from "../avatars/RoomAvatar"; import RoomName from "../elements/RoomName"; import ErrorDialog from "../dialogs/ErrorDialog"; import AccessibleButton from "../elements/AccessibleButton"; +import { Action } from "../../../dispatcher/actions"; interface IProps { event: MatrixEvent; @@ -91,7 +92,7 @@ export default class ThirdPartyMemberInfo extends React.Component { dis.dispatch({ - action: "view_3pid_invite", + action: Action.View3pidInvite, event: null, }); }; diff --git a/src/dispatcher/actions.ts b/src/dispatcher/actions.ts index 203b1fab730..fb1d360a6cf 100644 --- a/src/dispatcher/actions.ts +++ b/src/dispatcher/actions.ts @@ -376,4 +376,9 @@ export enum Action { * Fired when the room loaded. */ RoomLoaded = "room_loaded", + + /** + * Opens right panel with 3pid invite information + */ + View3pidInvite = "view_3pid_invite", } From 32349d3684a5223a64f2a6bb5b73b7822febcaff Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 27 Nov 2023 15:06:12 +1300 Subject: [PATCH 2/4] extract out action handler --- src/components/structures/RoomView.tsx | 9 ++---- .../action-handlers/View3pidInvite.ts | 29 +++++++++++++++++++ .../right-panel/action-handlers/index.ts | 17 +++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 src/stores/right-panel/action-handlers/View3pidInvite.ts create mode 100644 src/stores/right-panel/action-handlers/index.ts diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index be4744c46f5..2dcc161113f 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -131,6 +131,7 @@ import { isNotUndefined } from "../../Typeguards"; import { CancelAskToJoinPayload } from "../../dispatcher/payloads/CancelAskToJoinPayload"; import { SubmitAskToJoinPayload } from "../../dispatcher/payloads/SubmitAskToJoinPayload"; import RightPanelStore from "../../stores/right-panel/RightPanelStore"; +import { onView3pidInvite } from "../../stores/right-panel/action-handlers"; const DEBUG = false; const PREVENT_MULTIPLE_JITSI_WITHIN = 30_000; @@ -1273,13 +1274,7 @@ export class RoomView extends React.Component { } break; case Action.View3pidInvite: - if (payload.event) { - RightPanelStore.instance.showOrHidePanel(RightPanelPhases.Room3pidMemberInfo, { - memberInfoEvent: payload.event, - }); - } else { - RightPanelStore.instance.showOrHidePanel(RightPanelPhases.RoomMemberList); - } + onView3pidInvite(RightPanelStore.instance)(payload); break; } }; diff --git a/src/stores/right-panel/action-handlers/View3pidInvite.ts b/src/stores/right-panel/action-handlers/View3pidInvite.ts new file mode 100644 index 00000000000..fa87e659a91 --- /dev/null +++ b/src/stores/right-panel/action-handlers/View3pidInvite.ts @@ -0,0 +1,29 @@ +/* +Copyright 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { ActionPayload } from "../../../dispatcher/payloads"; +import RightPanelStore from "../RightPanelStore"; +import { RightPanelPhases } from "../RightPanelStorePhases"; + +export const onView3pidInvite = (rightPanelStore: RightPanelStore) => (payload: ActionPayload): void => { + if (payload.event) { + rightPanelStore.showOrHidePanel(RightPanelPhases.Room3pidMemberInfo, { + memberInfoEvent: payload.event, + }); + } else { + rightPanelStore.showOrHidePanel(RightPanelPhases.RoomMemberList); + } +} \ No newline at end of file diff --git a/src/stores/right-panel/action-handlers/index.ts b/src/stores/right-panel/action-handlers/index.ts new file mode 100644 index 00000000000..3ceb4874ec3 --- /dev/null +++ b/src/stores/right-panel/action-handlers/index.ts @@ -0,0 +1,17 @@ +/* +Copyright 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +export * from "./View3pidInvite"; \ No newline at end of file From 5800c6f39bbfa84f25dd8ba55508932aba95eab9 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 27 Nov 2023 16:00:52 +1300 Subject: [PATCH 3/4] push card instead, test --- src/components/structures/RoomView.tsx | 2 +- .../action-handlers/View3pidInvite.ts | 9 +-- .../right-panel/action-handlers/index.ts | 2 +- .../action-handlers/View3pidInvite-test.ts | 58 +++++++++++++++++++ 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 test/stores/right-panel/action-handlers/View3pidInvite-test.ts diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 2dcc161113f..2689fab9d47 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -1274,7 +1274,7 @@ export class RoomView extends React.Component { } break; case Action.View3pidInvite: - onView3pidInvite(RightPanelStore.instance)(payload); + onView3pidInvite(payload, RightPanelStore.instance); break; } }; diff --git a/src/stores/right-panel/action-handlers/View3pidInvite.ts b/src/stores/right-panel/action-handlers/View3pidInvite.ts index fa87e659a91..0fae9477dcb 100644 --- a/src/stores/right-panel/action-handlers/View3pidInvite.ts +++ b/src/stores/right-panel/action-handlers/View3pidInvite.ts @@ -18,12 +18,13 @@ import { ActionPayload } from "../../../dispatcher/payloads"; import RightPanelStore from "../RightPanelStore"; import { RightPanelPhases } from "../RightPanelStorePhases"; -export const onView3pidInvite = (rightPanelStore: RightPanelStore) => (payload: ActionPayload): void => { +export const onView3pidInvite = (payload: ActionPayload, rightPanelStore: RightPanelStore): void => { if (payload.event) { - rightPanelStore.showOrHidePanel(RightPanelPhases.Room3pidMemberInfo, { - memberInfoEvent: payload.event, + rightPanelStore.pushCard({ + phase: RightPanelPhases.Room3pidMemberInfo, + state: { memberInfoEvent: payload.event }, }); } else { rightPanelStore.showOrHidePanel(RightPanelPhases.RoomMemberList); } -} \ No newline at end of file +}; diff --git a/src/stores/right-panel/action-handlers/index.ts b/src/stores/right-panel/action-handlers/index.ts index 3ceb4874ec3..e5521522ce2 100644 --- a/src/stores/right-panel/action-handlers/index.ts +++ b/src/stores/right-panel/action-handlers/index.ts @@ -14,4 +14,4 @@ See the License for the specific language governing permissions and limitations under the License. */ -export * from "./View3pidInvite"; \ No newline at end of file +export * from "./View3pidInvite"; diff --git a/test/stores/right-panel/action-handlers/View3pidInvite-test.ts b/test/stores/right-panel/action-handlers/View3pidInvite-test.ts new file mode 100644 index 00000000000..01e8f2c75ca --- /dev/null +++ b/test/stores/right-panel/action-handlers/View3pidInvite-test.ts @@ -0,0 +1,58 @@ +/* +Copyright 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. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { MockedObject } from "jest-mock"; +import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix"; + +import { Action } from "../../../../src/dispatcher/actions"; +import { onView3pidInvite } from "../../../../src/stores/right-panel/action-handlers"; +import RightPanelStore from "../../../../src/stores/right-panel/RightPanelStore"; +import { RightPanelPhases } from "../../../../src/stores/right-panel/RightPanelStorePhases"; + +describe("onView3pidInvite()", () => { + let rightPanelStore!: MockedObject; + + beforeEach(() => { + rightPanelStore = { + pushCard: jest.fn(), + showOrHidePanel: jest.fn(), + } as unknown as MockedObject; + }); + + it("should display room member list when payload has a falsy event", () => { + const payload = { + action: Action.View3pidInvite, + }; + onView3pidInvite(payload, rightPanelStore); + + expect(rightPanelStore.showOrHidePanel).toHaveBeenCalledWith(RightPanelPhases.RoomMemberList); + expect(rightPanelStore.pushCard).not.toHaveBeenCalled(); + }); + + it("should push a 3pid member card on the right panel stack when payload has an event", () => { + const payload = { + action: Action.View3pidInvite, + event: new MatrixEvent({ type: EventType.RoomThirdPartyInvite }), + }; + onView3pidInvite(payload, rightPanelStore); + + expect(rightPanelStore.showOrHidePanel).not.toHaveBeenCalled(); + expect(rightPanelStore.pushCard).toHaveBeenCalledWith({ + phase: RightPanelPhases.Room3pidMemberInfo, + state: { memberInfoEvent: payload.event }, + }); + }); +}); From 50ab9c7fb174c705dd35e4caf0c1b594db447772 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 27 Nov 2023 16:13:27 +1300 Subject: [PATCH 4/4] comment --- src/stores/right-panel/action-handlers/View3pidInvite.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/stores/right-panel/action-handlers/View3pidInvite.ts b/src/stores/right-panel/action-handlers/View3pidInvite.ts index 0fae9477dcb..be61fd57451 100644 --- a/src/stores/right-panel/action-handlers/View3pidInvite.ts +++ b/src/stores/right-panel/action-handlers/View3pidInvite.ts @@ -18,6 +18,13 @@ import { ActionPayload } from "../../../dispatcher/payloads"; import RightPanelStore from "../RightPanelStore"; import { RightPanelPhases } from "../RightPanelStorePhases"; +/** + * Handle an Action.View3pidInvite action. + * Where payload has an event, open the right panel with 3pid room member info without clearing right panel history. + * Otherwise, 'close' the 3pid member info by displaying the room member list in the right panel. + * @param payload + * @param rightPanelStore store instance + */ export const onView3pidInvite = (payload: ActionPayload, rightPanelStore: RightPanelStore): void => { if (payload.event) { rightPanelStore.pushCard({