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
|
@ -19,11 +19,10 @@ import React, { ReactNode } from "react";
|
|||
import { EventStatus } from "matrix-js-sdk/src/models/event-status";
|
||||
import { MatrixEventEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
import { MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import Modal, { IHandle } from "../Modal";
|
||||
import Spinner from "../components/views/elements/Spinner";
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
import { _t } from "../languageHandler";
|
||||
import ErrorDialog from "../components/views/dialogs/ErrorDialog";
|
||||
import { isMetaSpace } from "../stores/spaces";
|
||||
|
@ -38,15 +37,19 @@ import { bulkSpaceBehaviour } from "./space";
|
|||
import { SdkContextClass } from "../contexts/SDKContext";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
|
||||
export async function leaveRoomBehaviour(roomId: string, retry = true, spinner = true): Promise<void> {
|
||||
export async function leaveRoomBehaviour(
|
||||
matrixClient: MatrixClient,
|
||||
roomId: string,
|
||||
retry = true,
|
||||
spinner = true,
|
||||
): Promise<void> {
|
||||
let spinnerModal: IHandle<any> | undefined;
|
||||
if (spinner) {
|
||||
spinnerModal = Modal.createDialog(Spinner, undefined, "mx_Dialog_spinner");
|
||||
}
|
||||
|
||||
const cli = MatrixClientPeg.get();
|
||||
let leavingAllVersions = true;
|
||||
const history = cli.getRoomUpgradeHistory(
|
||||
const history = matrixClient.getRoomUpgradeHistory(
|
||||
roomId,
|
||||
false,
|
||||
SettingsStore.getValue("feature_dynamic_room_predecessors"),
|
||||
|
@ -60,7 +63,7 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
|
|||
}
|
||||
}
|
||||
|
||||
const room = cli.getRoom(roomId);
|
||||
const room = matrixClient.getRoom(roomId);
|
||||
|
||||
// should not encounter this
|
||||
if (!room) {
|
||||
|
@ -97,9 +100,9 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
|
|||
let results: { [roomId: string]: Error | MatrixError | null } = {};
|
||||
if (!leavingAllVersions) {
|
||||
try {
|
||||
await cli.leave(roomId);
|
||||
await matrixClient.leave(roomId);
|
||||
} catch (e) {
|
||||
if (e?.data?.errcode) {
|
||||
if (e instanceof MatrixError) {
|
||||
const message = e.data.error || _t("Unexpected server error trying to leave the room");
|
||||
results[roomId] = Object.assign(new Error(message), { errcode: e.data.errcode, data: e.data });
|
||||
} else {
|
||||
|
@ -107,7 +110,7 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
|
|||
}
|
||||
}
|
||||
} else {
|
||||
results = await cli.leaveRoomChain(roomId, retry);
|
||||
results = await matrixClient.leaveRoomChain(roomId, retry);
|
||||
}
|
||||
|
||||
if (retry) {
|
||||
|
@ -116,7 +119,7 @@ export async function leaveRoomBehaviour(roomId: string, retry = true, spinner =
|
|||
) as MatrixError;
|
||||
if (limitExceededError) {
|
||||
await sleep(limitExceededError.data.retry_after_ms ?? 100);
|
||||
return leaveRoomBehaviour(roomId, false, false);
|
||||
return leaveRoomBehaviour(matrixClient, roomId, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,7 +189,7 @@ export const leaveSpace = (space: Room): void => {
|
|||
space,
|
||||
onFinished: async (leave: boolean, rooms: Room[]): Promise<void> => {
|
||||
if (!leave) return;
|
||||
await bulkSpaceBehaviour(space, rooms, (room) => leaveRoomBehaviour(room.roomId));
|
||||
await bulkSpaceBehaviour(space, rooms, (room) => leaveRoomBehaviour(space.client, room.roomId));
|
||||
|
||||
dis.dispatch<AfterLeaveRoomPayload>({
|
||||
action: Action.AfterLeaveRoom,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue