Eliminate the use of MatrixClientPeg in utils (#10910)
This commit is contained in:
parent
a0c2676c38
commit
30429df948
108 changed files with 409 additions and 325 deletions
|
@ -16,13 +16,13 @@ limitations under the License.
|
|||
|
||||
import classnames from "classnames";
|
||||
import { ComponentProps } from "react";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import defaultDispatcher from "../dispatcher/dispatcher";
|
||||
import { ActionPayload } from "../dispatcher/payloads";
|
||||
import Modal from "../Modal";
|
||||
import RoomSettingsDialog from "../components/views/dialogs/RoomSettingsDialog";
|
||||
import ForwardDialog from "../components/views/dialogs/ForwardDialog";
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
import { Action } from "../dispatcher/actions";
|
||||
import ReportEventDialog from "../components/views/dialogs/ReportEventDialog";
|
||||
import SpacePreferencesDialog from "../components/views/dialogs/SpacePreferencesDialog";
|
||||
|
@ -43,18 +43,21 @@ export class DialogOpener {
|
|||
public static readonly instance = new DialogOpener();
|
||||
|
||||
private isRegistered = false;
|
||||
private matrixClient?: MatrixClient;
|
||||
|
||||
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(): void {
|
||||
public prepare(matrixClient: MatrixClient): void {
|
||||
this.matrixClient = matrixClient;
|
||||
if (this.isRegistered) return;
|
||||
defaultDispatcher.register(this.onDispatch);
|
||||
this.isRegistered = true;
|
||||
}
|
||||
|
||||
private onDispatch = (payload: ActionPayload): void => {
|
||||
if (!this.matrixClient) return;
|
||||
switch (payload.action) {
|
||||
case "open_room_settings":
|
||||
Modal.createDialog(
|
||||
|
@ -70,7 +73,7 @@ export class DialogOpener {
|
|||
break;
|
||||
case Action.OpenForwardDialog:
|
||||
Modal.createDialog(ForwardDialog, {
|
||||
matrixClient: MatrixClientPeg.get(),
|
||||
matrixClient: this.matrixClient,
|
||||
event: payload.event,
|
||||
permalinkCreator: payload.permalinkCreator,
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue