Skip to content

Commit

Permalink
feat(#2): disable commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ifaouibadi committed Dec 13, 2023
1 parent e3055c7 commit 88f147f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
4 changes: 3 additions & 1 deletion components.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"src/components/views/auth/AuthFooter.tsx": "src/components/views/auth/VectorAuthFooter.tsx",
"src/components/views/auth/AuthHeaderLogo.tsx": "src/components/views/auth/VectorAuthHeaderLogo.tsx",
"src/components/views/auth/AuthPage.tsx": "src/components/views/auth/VectorAuthPage.tsx"
"src/components/views/auth/AuthPage.tsx": "src/components/views/auth/VectorAuthPage.tsx",
"src/components/views/rooms/Autocomplete.tsx": "src/components/views/rooms/Autocomplete.tsx",
"src/editor/commands.tsx": "src/editor/commands.tsx"
}
31 changes: 31 additions & 0 deletions src/components/views/rooms/Autocomplete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";

export const generateCompletionDomId = (n: number): string => `mx_Autocomplete_Completion_${n}`;

export default class Autocomplete extends React.PureComponent {
public constructor(props: {} | Readonly<{}>) {
super(props);

this.state = {
// list of completionResults, each containing completions
completions: [],

// array of completions, so we can look up current selection by offset quickly
completionList: [],

// how far down the completion list we are (THIS IS 1-INDEXED!)
selectionOffset: 1,

// whether we should show completions if they're available
shouldShowCompletions: true,

hide: false,

forceComplete: false,
};
}

public render(): React.ReactNode {
return null;
}
}
34 changes: 34 additions & 0 deletions src/editor/commands.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { IContent, MatrixClient } from "matrix-js-sdk/src/matrix";
import { Command, getCommand } from "matrix-react-sdk/src/SlashCommands";
import EditorModel from "matrix-react-sdk/src/editor/model";
import { Type } from "matrix-react-sdk/src/editor/parts";

export function isSlashCommand(model: EditorModel): boolean {
return false;
}

export function getSlashCommand(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
if (part.type === Type.UserPill || part.type === Type.RoomPill) {
return text + part.resourceId;
}
return text + part.text;
}, "");
const { cmd, args } = getCommand(commandText);
return [cmd, args, commandText];
}

export async function runSlashCommand(
matrixClient: MatrixClient,
cmd: Command,
args: string | undefined,
roomId: string,
threadId: string | null,
): Promise<[content: IContent | null, success: boolean]> {
return [null, false];
}

export async function shouldSendAnyway(commandText: string): Promise<boolean> {
return true;
}

0 comments on commit 88f147f

Please sign in to comment.