2022-03-25 05:55:57 +08:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2022-06-02 21:59:40 +08:00
|
|
|
import classnames from "classnames";
|
|
|
|
|
2022-03-25 05:55:57 +08:00
|
|
|
import defaultDispatcher from "../dispatcher/dispatcher";
|
|
|
|
import { ActionPayload } from "../dispatcher/payloads";
|
|
|
|
import Modal from "../Modal";
|
|
|
|
import RoomSettingsDialog from "../components/views/dialogs/RoomSettingsDialog";
|
2022-03-25 06:00:47 +08:00
|
|
|
import ForwardDialog from "../components/views/dialogs/ForwardDialog";
|
|
|
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
|
|
|
import { Action } from "../dispatcher/actions";
|
2022-03-25 06:02:33 +08:00
|
|
|
import ReportEventDialog from "../components/views/dialogs/ReportEventDialog";
|
2022-03-25 06:13:36 +08:00
|
|
|
import SpacePreferencesDialog from "../components/views/dialogs/SpacePreferencesDialog";
|
|
|
|
import SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog";
|
2022-03-25 06:30:53 +08:00
|
|
|
import InviteDialog from "../components/views/dialogs/InviteDialog";
|
2022-03-25 08:01:09 +08:00
|
|
|
import AddExistingToSpaceDialog from "../components/views/dialogs/AddExistingToSpaceDialog";
|
|
|
|
import { ButtonEvent } from "../components/views/elements/AccessibleButton";
|
|
|
|
import PosthogTrackers from "../PosthogTrackers";
|
|
|
|
import { showAddExistingSubspace, showCreateNewRoom } from "./space";
|
2022-10-19 20:07:03 +08:00
|
|
|
import { SdkContextClass } from "../contexts/SDKContext";
|
2022-03-25 05:55:57 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Auxiliary class to listen for dialog opening over the dispatcher and
|
|
|
|
* open the required dialogs. Not all dialogs run through here, but the
|
|
|
|
* ones which cause import cycles are good candidates.
|
|
|
|
*/
|
|
|
|
export class DialogOpener {
|
|
|
|
public static readonly instance = new DialogOpener();
|
|
|
|
|
|
|
|
private isRegistered = false;
|
|
|
|
|
|
|
|
private constructor() {
|
|
|
|
}
|
|
|
|
|
|
|
|
// We could do this in the constructor, but then we wouldn't have
|
|
|
|
// a function to call from Lifecycle to capture the class.
|
|
|
|
public prepare() {
|
|
|
|
if (this.isRegistered) return;
|
|
|
|
defaultDispatcher.register(this.onDispatch);
|
|
|
|
this.isRegistered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private onDispatch = (payload: ActionPayload) => {
|
|
|
|
switch (payload.action) {
|
|
|
|
case 'open_room_settings':
|
2022-06-15 00:51:51 +08:00
|
|
|
Modal.createDialog(RoomSettingsDialog, {
|
2022-10-19 20:07:03 +08:00
|
|
|
roomId: payload.room_id || SdkContextClass.instance.roomViewStore.getRoomId(),
|
2022-03-25 05:55:57 +08:00
|
|
|
initialTabId: payload.initial_tab_id,
|
|
|
|
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
|
|
|
break;
|
2022-03-25 06:00:47 +08:00
|
|
|
case Action.OpenForwardDialog:
|
2022-06-15 00:51:51 +08:00
|
|
|
Modal.createDialog(ForwardDialog, {
|
2022-03-25 06:00:47 +08:00
|
|
|
matrixClient: MatrixClientPeg.get(),
|
|
|
|
event: payload.event,
|
|
|
|
permalinkCreator: payload.permalinkCreator,
|
|
|
|
});
|
|
|
|
break;
|
2022-03-25 06:02:33 +08:00
|
|
|
case Action.OpenReportEventDialog:
|
2022-06-15 00:51:51 +08:00
|
|
|
Modal.createDialog(ReportEventDialog, {
|
2022-04-08 22:19:14 +08:00
|
|
|
mxEvent: payload.event,
|
2022-03-25 06:02:33 +08:00
|
|
|
}, 'mx_Dialog_reportEvent');
|
|
|
|
break;
|
2022-03-25 06:13:36 +08:00
|
|
|
case Action.OpenSpacePreferences:
|
2022-06-15 00:51:51 +08:00
|
|
|
Modal.createDialog(SpacePreferencesDialog, {
|
2022-03-25 06:13:36 +08:00
|
|
|
initialTabId: payload.initalTabId,
|
|
|
|
space: payload.space,
|
|
|
|
}, null, false, true);
|
|
|
|
break;
|
|
|
|
case Action.OpenSpaceSettings:
|
2022-06-15 00:51:51 +08:00
|
|
|
Modal.createDialog(SpaceSettingsDialog, {
|
2022-03-25 06:13:36 +08:00
|
|
|
matrixClient: payload.space.client,
|
|
|
|
space: payload.space,
|
|
|
|
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
|
|
|
break;
|
2022-03-25 06:30:53 +08:00
|
|
|
case Action.OpenInviteDialog:
|
2022-06-15 00:51:51 +08:00
|
|
|
Modal.createDialog(InviteDialog, {
|
2022-03-25 06:30:53 +08:00
|
|
|
kind: payload.kind,
|
|
|
|
call: payload.call,
|
|
|
|
roomId: payload.roomId,
|
2022-06-02 21:59:40 +08:00
|
|
|
}, classnames("mx_InviteDialog_flexWrapper", payload.className), false, true).finished
|
|
|
|
.then((results) => {
|
|
|
|
payload.onFinishedCallback?.(results);
|
|
|
|
});
|
2022-03-25 06:30:53 +08:00
|
|
|
break;
|
2022-03-25 08:01:09 +08:00
|
|
|
case Action.OpenAddToExistingSpaceDialog: {
|
|
|
|
const space = payload.space;
|
2022-06-15 00:51:51 +08:00
|
|
|
Modal.createDialog(
|
2022-03-25 08:01:09 +08:00
|
|
|
AddExistingToSpaceDialog,
|
|
|
|
{
|
|
|
|
onCreateRoomClick: (ev: ButtonEvent) => {
|
|
|
|
showCreateNewRoom(space);
|
|
|
|
PosthogTrackers.trackInteraction("WebAddExistingToSpaceDialogCreateRoomButton", ev);
|
|
|
|
},
|
|
|
|
onAddSubspaceClick: () => showAddExistingSubspace(space),
|
|
|
|
space,
|
|
|
|
onFinished: (added: boolean) => {
|
2022-10-19 20:07:03 +08:00
|
|
|
if (added && SdkContextClass.instance.roomViewStore.getRoomId() === space.roomId) {
|
2022-03-25 08:01:09 +08:00
|
|
|
defaultDispatcher.fire(Action.UpdateSpaceHierarchy);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"mx_AddExistingToSpaceDialog_wrapper",
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2022-03-25 05:55:57 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|