From c760ba083947bcf8e89019a35966d1b252f94c30 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 25 Sep 2019 17:30:01 +0200 Subject: [PATCH] make command detection more resilient --- src/components/views/rooms/SendMessageComposer.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/SendMessageComposer.js b/src/components/views/rooms/SendMessageComposer.js index f6e5830329..2717ff58c5 100644 --- a/src/components/views/rooms/SendMessageComposer.js +++ b/src/components/views/rooms/SendMessageComposer.js @@ -170,7 +170,19 @@ export default class SendMessageComposer extends React.Component { _isSlashCommand() { const parts = this.model.parts; - return parts.length && parts[0].type === "command"; + const firstPart = parts[0]; + if (firstPart) { + if (firstPart.type === "command") { + return true; + } + // be extra resilient when somehow the AutocompleteWrapperModel or + // CommandPartCreator fails to insert a command part, so we don't send + // a command as a message + if (firstPart.type === "plain" && firstPart.text.startsWith("/")) { + return true; + } + } + return false; } async _runSlashCommand() {