diff --git a/src/components/views/dialogs/SlashCommandHelpDialog.tsx b/src/components/views/dialogs/SlashCommandHelpDialog.tsx index f3059d278e..0ac1a0de0d 100644 --- a/src/components/views/dialogs/SlashCommandHelpDialog.tsx +++ b/src/components/views/dialogs/SlashCommandHelpDialog.tsx @@ -13,6 +13,11 @@ import { type Command, CommandCategories, Commands } from "../../../SlashCommand import InfoDialog from "./InfoDialog"; import { MatrixClientPeg } from "../../../MatrixClientPeg"; +/** + * Props for {@link SlashCommandHelpDialog} + * @param roomId - The room ID to check whether commands are enabled + * @param onFinished - Callback called when the dialog is closed + */ interface IProps { roomId: string; onFinished(): void; diff --git a/src/editor/commands.tsx b/src/editor/commands.tsx index ecd12b6e0b..6346785755 100644 --- a/src/editor/commands.tsx +++ b/src/editor/commands.tsx @@ -38,6 +38,12 @@ export function isSlashCommand(model: EditorModel): boolean { return false; } +/** + * Get the slash command and its arguments from the editor model + * @param roomId - The room ID to check whether the command is enabled + * @param model - The editor model + * @returns A tuple of the command (or undefined if not found), the arguments (or undefined), and the full command text + */ export function getSlashCommand(roomId: string, model: EditorModel): [Command | undefined, string | undefined, string] { const commandText = model.parts.reduce((text, part) => { // use mxid to textify user pills in a command and room alias/id for room pills diff --git a/src/slash-commands/command.ts b/src/slash-commands/command.ts index ed18ae58e7..9619c514dd 100644 --- a/src/slash-commands/command.ts +++ b/src/slash-commands/command.ts @@ -18,6 +18,14 @@ import { _t, type TranslationKey, UserFriendlyError } from "../languageHandler"; import { PosthogAnalytics } from "../PosthogAnalytics"; import { CommandCategories, type RunResult } from "./interface"; +/** + * The function signature for the run function of a {@link Command} + * @param matrixClient - The Matrix client + * @param roomId - The room ID where the command is run + * @param threadId - The thread ID where the command is run, or null for room timeline + * @param args - The arguments passed to the command + * @returns The result of running the command + */ type RunFn = ( this: Command, matrixClient: MatrixClient, @@ -26,6 +34,19 @@ type RunFn = ( args?: string, ) => RunResult; +/** + * Options for {@link Command} + * @param command - The command name, e.g. "me" for the /me command + * @param aliases - Alternative names for the command + * @param args - The arguments for the command, e.g. "" for the /me command + * @param description - A translation key describing the command + * @param analyticsName - The name to use for analytics tracking + * @param runFn - The function to execute when the command is run + * @param category - The category of the command, e.g. CommandCategories.emoji + * @param hideCompletionAfterSpace - Whether to hide autocomplete after a space is typed + * @param isEnabled - A function to determine if the command is enabled in a given context + * @param renderingTypes - The rendering types (room/thread) where this command is valid + */ interface ICommandOpts { command: string; aliases?: string[]; diff --git a/src/slash-commands/utils.ts b/src/slash-commands/utils.ts index 0f019bac60..a96a324d5d 100644 --- a/src/slash-commands/utils.ts +++ b/src/slash-commands/utils.ts @@ -29,6 +29,12 @@ export function successSync(value: any): RunResult { return success(Promise.resolve(value)); } +/** + * Check whether the user can affect power levels in the given room + * @param cli - The Matrix client + * @param roomId - The room ID + * @returns True if the user can affect power levels, false otherwise + */ export const canAffectPowerlevels = (cli: MatrixClient | null, roomId: string | null): boolean => { if (!cli || !roomId) return false; const room = cli?.getRoom(roomId);