Prompt to send command as message (#1435)
authorCadence Ember <cloudrac3r@vivaldi.net>
Fri, 6 Oct 2023 02:48:48 +0000 (15:48 +1300)
committerGitHub <noreply@github.com>
Fri, 6 Oct 2023 02:48:48 +0000 (08:18 +0530)
src/app/organisms/room/RoomViewInput.jsx

index c43eb601619b460190a6aef30c9c154a93e3010c..3fb780a4de5c6c2ae582767c53ba21821f31b2c1 100644 (file)
@@ -206,28 +206,36 @@ function RoomViewInput({
     if (replyTo !== null) setReplyTo(null);
   };
 
-  const processCommand = (cmdBody) => {
+  /** Return true if a command was executed. */
+  const processCommand = async (cmdBody) => {
     const spaceIndex = cmdBody.indexOf(' ');
     const cmdName = cmdBody.slice(1, spaceIndex > -1 ? spaceIndex : undefined);
     const cmdData = spaceIndex > -1 ? cmdBody.slice(spaceIndex + 1) : '';
     if (!commands[cmdName]) {
-      confirmDialog('Invalid Command', `"${cmdName}" is not a valid command.`, 'Alright');
-      return;
+      const sendAsMessage = await confirmDialog('Invalid Command', `"${cmdName}" is not a valid command. Did you mean to send this as a message?`, 'Send as message');
+      if (sendAsMessage) {
+        sendBody(cmdBody);
+        return true;
+      }
+      return false;
     }
     if (['me', 'shrug', 'plain'].includes(cmdName)) {
       commands[cmdName].exe(roomId, cmdData, sendBody);
-      return;
+      return true;
     }
     commands[cmdName].exe(roomId, cmdData);
+    return true;
   };
 
   const sendMessage = async () => {
     requestAnimationFrame(() => deactivateCmdAndEmit());
     const msgBody = textAreaRef.current.value.trim();
     if (msgBody.startsWith('/')) {
-      processCommand(msgBody.trim());
-      textAreaRef.current.value = '';
-      textAreaRef.current.style.height = 'unset';
+      const executed = await processCommand(msgBody.trim());
+      if (executed) {
+        textAreaRef.current.value = '';
+        textAreaRef.current.style.height = 'unset';
+      }
       return;
     }
     if (msgBody === '' && attachment === null) return;