Keep draft in composer when a slash command syntax errors (#8811)
This commit is contained in:
parent
4171c008a4
commit
3f99f594de
3 changed files with 15 additions and 13 deletions
|
@ -332,13 +332,14 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
|
||||||
const [cmd, args, commandText] = getSlashCommand(this.model);
|
const [cmd, args, commandText] = getSlashCommand(this.model);
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
const threadId = editedEvent?.getThread()?.id || null;
|
const threadId = editedEvent?.getThread()?.id || null;
|
||||||
if (cmd.category === CommandCategories.messages) {
|
const [content, commandSuccessful] = await runSlashCommand(cmd, args, roomId, threadId);
|
||||||
editContent["m.new_content"] = await runSlashCommand(cmd, args, roomId, threadId);
|
if (!commandSuccessful) {
|
||||||
if (!editContent["m.new_content"]) {
|
|
||||||
return; // errored
|
return; // errored
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmd.category === CommandCategories.messages) {
|
||||||
|
editContent["m.new_content"] = content;
|
||||||
} else {
|
} else {
|
||||||
runSlashCommand(cmd, args, roomId, threadId);
|
|
||||||
shouldSend = false;
|
shouldSend = false;
|
||||||
}
|
}
|
||||||
} else if (!await shouldSendAnyway(commandText)) {
|
} else if (!await shouldSendAnyway(commandText)) {
|
||||||
|
|
|
@ -351,12 +351,13 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
||||||
? this.props.relation?.event_id
|
? this.props.relation?.event_id
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (cmd.category === CommandCategories.messages) {
|
let commandSuccessful: boolean;
|
||||||
content = await runSlashCommand(cmd, args, this.props.room.roomId, threadId);
|
[content, commandSuccessful] = await runSlashCommand(cmd, args, this.props.room.roomId, threadId);
|
||||||
if (!content) {
|
if (!commandSuccessful) {
|
||||||
return; // errored
|
return; // errored
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmd.category === CommandCategories.messages) {
|
||||||
attachRelation(content, this.props.relation);
|
attachRelation(content, this.props.relation);
|
||||||
if (replyToEvent) {
|
if (replyToEvent) {
|
||||||
addReplyToMessageContent(content, replyToEvent, {
|
addReplyToMessageContent(content, replyToEvent, {
|
||||||
|
@ -365,7 +366,6 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
runSlashCommand(cmd, args, this.props.room.roomId, threadId);
|
|
||||||
shouldSend = false;
|
shouldSend = false;
|
||||||
}
|
}
|
||||||
} else if (!await shouldSendAnyway(commandText)) {
|
} else if (!await shouldSendAnyway(commandText)) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ export async function runSlashCommand(
|
||||||
args: string,
|
args: string,
|
||||||
roomId: string,
|
roomId: string,
|
||||||
threadId: string | null,
|
threadId: string | null,
|
||||||
): Promise<IContent | null> {
|
): Promise<[content: IContent | null, success: boolean]> {
|
||||||
const result = cmd.run(roomId, threadId, args);
|
const result = cmd.run(roomId, threadId, args);
|
||||||
let messageContent: IContent | null = null;
|
let messageContent: IContent | null = null;
|
||||||
let error = result.error;
|
let error = result.error;
|
||||||
|
@ -96,9 +96,10 @@ export async function runSlashCommand(
|
||||||
title: _t(title),
|
title: _t(title),
|
||||||
description: errText,
|
description: errText,
|
||||||
});
|
});
|
||||||
|
return [null, false];
|
||||||
} else {
|
} else {
|
||||||
logger.log("Command success.");
|
logger.log("Command success.");
|
||||||
if (messageContent) return messageContent;
|
return [messageContent, true];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue