diff --git a/src/components/views/context_menus/MessageContextMenu.tsx b/src/components/views/context_menus/MessageContextMenu.tsx index cffd83a4e0..00b0a69778 100644 --- a/src/components/views/context_menus/MessageContextMenu.tsx +++ b/src/components/views/context_menus/MessageContextMenu.tsx @@ -33,7 +33,6 @@ import { isUrlPermitted } from '../../../HtmlUtils'; import { isContentActionable } from '../../../utils/EventUtils'; import IconizedContextMenu, { IconizedContextMenuOption, IconizedContextMenuOptionList } from './IconizedContextMenu'; import { ReadPinsEventId } from "../right_panel/types"; -import ForwardDialog from "../dialogs/ForwardDialog"; import { Action } from "../../../dispatcher/actions"; import ReportEventDialog from '../dialogs/ReportEventDialog'; import ViewSource from '../../structures/ViewSource'; @@ -47,6 +46,7 @@ import { WidgetLayoutStore } from '../../../stores/widgets/WidgetLayoutStore'; import EndPollDialog from '../dialogs/EndPollDialog'; import { isPollEnded } from '../messages/MPollBody'; import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload"; +import { OpenForwardDialogPayload } from "../../../dispatcher/payloads/OpenForwardDialogPayload"; import { createMapSiteLink } from '../../../utils/location'; export function canCancel(status: EventStatus): boolean { @@ -177,11 +177,11 @@ export default class MessageContextMenu extends React.Component }; private onForwardClick = (): void => { - Modal.createTrackedDialog('Forward Message', '', ForwardDialog, { - matrixClient: MatrixClientPeg.get(), + dis.dispatch({ + action: Action.OpenForwardDialog, event: this.props.mxEvent, permalinkCreator: this.props.permalinkCreator, - }); + } as OpenForwardDialogPayload); this.closeMenu(); }; diff --git a/src/dispatcher/actions.ts b/src/dispatcher/actions.ts index 5dbdd24540..12053e204d 100644 --- a/src/dispatcher/actions.ts +++ b/src/dispatcher/actions.ts @@ -265,4 +265,10 @@ export enum Action { * Payload: ActiveRoomChangedPayload */ ActiveRoomChanged = "active_room_changed", + + /** + * Fired when the forward dialog needs to be opened. + * Payload: OpenForwardDialogPayload + */ + OpenForwardDialog = "open_forward_dialog", } diff --git a/src/dispatcher/payloads/OpenForwardDialogPayload.ts b/src/dispatcher/payloads/OpenForwardDialogPayload.ts new file mode 100644 index 0000000000..4a5a9b1c84 --- /dev/null +++ b/src/dispatcher/payloads/OpenForwardDialogPayload.ts @@ -0,0 +1,29 @@ +/* +Copyright 2022 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 { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { Optional } from "matrix-events-sdk"; + +import { Action } from "../actions"; +import { ActionPayload } from "../payloads"; +import { RoomPermalinkCreator } from "../../utils/permalinks/Permalinks"; + +export interface OpenForwardDialogPayload extends ActionPayload { + action: Action.OpenForwardDialog; + + event: MatrixEvent; + permalinkCreator: Optional; +} diff --git a/src/utils/DialogOpener.ts b/src/utils/DialogOpener.ts index 3908a5af1e..ca4ab85b13 100644 --- a/src/utils/DialogOpener.ts +++ b/src/utils/DialogOpener.ts @@ -19,6 +19,9 @@ import { ActionPayload } from "../dispatcher/payloads"; import Modal from "../Modal"; import RoomSettingsDialog from "../components/views/dialogs/RoomSettingsDialog"; import { RoomViewStore } from "../stores/RoomViewStore"; +import ForwardDialog from "../components/views/dialogs/ForwardDialog"; +import { MatrixClientPeg } from "../MatrixClientPeg"; +import { Action } from "../dispatcher/actions"; /** * Auxiliary class to listen for dialog opening over the dispatcher and @@ -49,6 +52,13 @@ export class DialogOpener { initialTabId: payload.initial_tab_id, }, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true); break; + case Action.OpenForwardDialog: + Modal.createTrackedDialog('Forward Message', '', ForwardDialog, { + matrixClient: MatrixClientPeg.get(), + event: payload.event, + permalinkCreator: payload.permalinkCreator, + }); + break; } }; }