mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
Merge pull request #3479 from matrix-org/bwindels/command-detection-resilience
Fix: make command detection more resilient
This commit is contained in:
commit
99961df9d0
1 changed files with 17 additions and 1 deletions
|
@ -174,11 +174,27 @@ 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() {
|
||||
const commandText = this.model.parts.reduce((text, part) => {
|
||||
// use mxid to textify user pills in a command
|
||||
if (part.type === "user-pill") {
|
||||
return text + part.resourceId;
|
||||
}
|
||||
return text + part.text;
|
||||
}, "");
|
||||
const cmd = processCommandInput(this.props.room.roomId, commandText);
|
||||
|
|
Loading…
Reference in a new issue