Prompt to send command as message (#1435)
This commit is contained in:
parent
3a95d0da01
commit
f9b895b32c
1 changed files with 15 additions and 7 deletions
|
@ -206,28 +206,36 @@ function RoomViewInput({
|
||||||
if (replyTo !== null) setReplyTo(null);
|
if (replyTo !== null) setReplyTo(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const processCommand = (cmdBody) => {
|
/** Return true if a command was executed. */
|
||||||
|
const processCommand = async (cmdBody) => {
|
||||||
const spaceIndex = cmdBody.indexOf(' ');
|
const spaceIndex = cmdBody.indexOf(' ');
|
||||||
const cmdName = cmdBody.slice(1, spaceIndex > -1 ? spaceIndex : undefined);
|
const cmdName = cmdBody.slice(1, spaceIndex > -1 ? spaceIndex : undefined);
|
||||||
const cmdData = spaceIndex > -1 ? cmdBody.slice(spaceIndex + 1) : '';
|
const cmdData = spaceIndex > -1 ? cmdBody.slice(spaceIndex + 1) : '';
|
||||||
if (!commands[cmdName]) {
|
if (!commands[cmdName]) {
|
||||||
confirmDialog('Invalid Command', `"${cmdName}" is not a valid command.`, 'Alright');
|
const sendAsMessage = await confirmDialog('Invalid Command', `"${cmdName}" is not a valid command. Did you mean to send this as a message?`, 'Send as message');
|
||||||
return;
|
if (sendAsMessage) {
|
||||||
|
sendBody(cmdBody);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (['me', 'shrug', 'plain'].includes(cmdName)) {
|
if (['me', 'shrug', 'plain'].includes(cmdName)) {
|
||||||
commands[cmdName].exe(roomId, cmdData, sendBody);
|
commands[cmdName].exe(roomId, cmdData, sendBody);
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
commands[cmdName].exe(roomId, cmdData);
|
commands[cmdName].exe(roomId, cmdData);
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendMessage = async () => {
|
const sendMessage = async () => {
|
||||||
requestAnimationFrame(() => deactivateCmdAndEmit());
|
requestAnimationFrame(() => deactivateCmdAndEmit());
|
||||||
const msgBody = textAreaRef.current.value.trim();
|
const msgBody = textAreaRef.current.value.trim();
|
||||||
if (msgBody.startsWith('/')) {
|
if (msgBody.startsWith('/')) {
|
||||||
processCommand(msgBody.trim());
|
const executed = await processCommand(msgBody.trim());
|
||||||
textAreaRef.current.value = '';
|
if (executed) {
|
||||||
textAreaRef.current.style.height = 'unset';
|
textAreaRef.current.value = '';
|
||||||
|
textAreaRef.current.style.height = 'unset';
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msgBody === '' && attachment === null) return;
|
if (msgBody === '' && attachment === null) return;
|
||||||
|
|
Loading…
Reference in a new issue