Move the upgraderoom command into its own subdirectory of slash-commands (#31941)

* Move the code for running the upgrade command into its subdir

* Replace use of deprecated currentState property in runUpgradeRoomCommand

* Move upgraderoom command options into their own file

* Move upgraderoom tests into their own file and add a couple
This commit is contained in:
Andy Balaam
2026-02-03 15:02:54 +00:00
committed by GitHub
parent a1be203683
commit 6d7def7b10
5 changed files with 231 additions and 114 deletions
+2 -49
View File
@@ -44,9 +44,7 @@ import { UIComponent, UIFeature } from "./settings/UIFeature";
import { CHAT_EFFECTS } from "./effects";
import LegacyCallHandler from "./LegacyCallHandler";
import { guessAndSetDMRoom } from "./Rooms";
import { upgradeRoom } from "./utils/RoomUpgrade";
import DevtoolsDialog from "./components/views/dialogs/DevtoolsDialog";
import RoomUpgradeWarningDialog from "./components/views/dialogs/RoomUpgradeWarningDialog";
import InfoDialog from "./components/views/dialogs/InfoDialog";
import SlashCommandHelpDialog from "./components/views/dialogs/SlashCommandHelpDialog";
import { shouldShowComponent } from "./customisations/helpers/UIComponents";
@@ -61,7 +59,7 @@ import { CommandCategories } from "./slash-commands/interface";
import { Command } from "./slash-commands/command";
import { goto, join } from "./slash-commands/join";
import { manuallyVerifyDevice } from "./components/views/dialogs/ManualDeviceKeyVerificationDialog";
import { parseUpgradeRoomArgs } from "./slash-commands/upgraderoom/parseUpgradeRoomArgs";
import upgraderoom from "./slash-commands/upgraderoom/upgraderoom";
export { CommandCategories, Command };
@@ -145,52 +143,7 @@ export const Commands = [
},
category: CommandCategories.messages,
}),
new Command({
command: "upgraderoom",
args: "<new_version> [<additional-creator-user-id> ...]",
description: _td("slash_command|upgraderoom"),
isEnabled: (cli) => !isCurrentLocalRoom(cli),
runFn: function (cli, roomId, threadId, args) {
if (!args) {
return reject(this.getUsage());
}
const parsedArgs = parseUpgradeRoomArgs(args);
if (parsedArgs) {
const room = cli.getRoom(roomId);
if (!room?.currentState.mayClientSendStateEvent("m.room.tombstone", cli)) {
return reject(new UserFriendlyError("slash_command|upgraderoom_permission_error"));
}
const { finished } = Modal.createDialog(
RoomUpgradeWarningDialog,
{ roomId: roomId, targetVersion: parsedArgs.targetVersion },
/*className=*/ undefined,
/*isPriority=*/ false,
/*isStatic=*/ true,
);
return success(
finished.then(async ([resp]): Promise<void> => {
if (!resp?.continue) return;
await upgradeRoom(
room,
parsedArgs.targetVersion,
resp.invite,
true,
true,
false,
undefined,
false,
parsedArgs.additionalCreators,
);
}),
);
}
return reject(this.getUsage());
},
category: CommandCategories.admin,
renderingTypes: [TimelineRenderingType.Room],
}),
upgraderoom,
new Command({
command: "jumptodate",
args: "<YYYY-MM-DD>",
@@ -0,0 +1,64 @@
/*
* Copyright 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import { EventTimeline, type MatrixClient } from "matrix-js-sdk/src/matrix";
import Modal from "../../Modal";
import RoomUpgradeWarningDialog from "../../components/views/dialogs/RoomUpgradeWarningDialog";
import { type Command } from "../command";
import { UserFriendlyError } from "../../languageHandler";
import { parseUpgradeRoomArgs } from "./parseUpgradeRoomArgs";
import { reject, success } from "../utils";
import { type RunResult } from "../interface";
import { upgradeRoom } from "../../utils/RoomUpgrade";
export function runUpgradeRoomCommand(
command: Command,
cli: MatrixClient,
roomId: string,
_threadId: string | null,
args?: string,
): RunResult {
if (!args) {
return reject(command.getUsage());
}
const parsedArgs = parseUpgradeRoomArgs(args);
if (parsedArgs) {
const room = cli.getRoom(roomId);
if (
!room?.getLiveTimeline().getState(EventTimeline.FORWARDS)?.mayClientSendStateEvent("m.room.tombstone", cli)
) {
return reject(new UserFriendlyError("slash_command|upgraderoom_permission_error"));
}
const { finished } = Modal.createDialog(
RoomUpgradeWarningDialog,
{ roomId: roomId, targetVersion: parsedArgs.targetVersion },
/*className=*/ undefined,
/*isPriority=*/ false,
/*isStatic=*/ true,
);
return success(
finished.then(async ([resp]): Promise<void> => {
if (!resp?.continue) return;
await upgradeRoom(
room,
parsedArgs.targetVersion,
resp.invite,
true,
true,
false,
undefined,
false,
parsedArgs.additionalCreators,
);
}),
);
}
return reject(command.getUsage());
}
@@ -0,0 +1,29 @@
/*
* Copyright 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import { type MatrixClient } from "matrix-js-sdk/src/matrix";
import { _td } from "../../languageHandler";
import { isCurrentLocalRoom } from "../utils";
import { runUpgradeRoomCommand } from "./runUpgradeRoomCommand";
import { Command } from "../command";
import { CommandCategories, type RunResult } from "../interface";
import { TimelineRenderingType } from "../../contexts/RoomContext";
const upgraderoom = new Command({
command: "upgraderoom",
args: "<new_version> [<additional-creator-user-id> ...]",
description: _td("slash_command|upgraderoom"),
isEnabled: (cli: MatrixClient) => !isCurrentLocalRoom(cli),
runFn: function (cli: MatrixClient, roomId: string, threadId: string | null, args?: string): RunResult {
return runUpgradeRoomCommand(this, cli, roomId, threadId, args);
},
category: CommandCategories.admin,
renderingTypes: [TimelineRenderingType.Room],
});
export default upgraderoom;