Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Keep draft in composer when a slash command syntax errors (#8811)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Jun 10, 2022
1 parent 4171c00 commit 3f99f59
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
11 changes: 6 additions & 5 deletions src/components/views/rooms/EditMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,14 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
const [cmd, args, commandText] = getSlashCommand(this.model);
if (cmd) {
const threadId = editedEvent?.getThread()?.id || null;
const [content, commandSuccessful] = await runSlashCommand(cmd, args, roomId, threadId);
if (!commandSuccessful) {
return; // errored
}

if (cmd.category === CommandCategories.messages) {
editContent["m.new_content"] = await runSlashCommand(cmd, args, roomId, threadId);
if (!editContent["m.new_content"]) {
return; // errored
}
editContent["m.new_content"] = content;
} else {
runSlashCommand(cmd, args, roomId, threadId);
shouldSend = false;
}
} else if (!await shouldSendAnyway(commandText)) {
Expand Down
12 changes: 6 additions & 6 deletions src/components/views/rooms/SendMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,13 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
? this.props.relation?.event_id
: null;

if (cmd.category === CommandCategories.messages) {
content = await runSlashCommand(cmd, args, this.props.room.roomId, threadId);
if (!content) {
return; // errored
}
let commandSuccessful: boolean;
[content, commandSuccessful] = await runSlashCommand(cmd, args, this.props.room.roomId, threadId);
if (!commandSuccessful) {
return; // errored
}

if (cmd.category === CommandCategories.messages) {
attachRelation(content, this.props.relation);
if (replyToEvent) {
addReplyToMessageContent(content, replyToEvent, {
Expand All @@ -365,7 +366,6 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
});
}
} else {
runSlashCommand(cmd, args, this.props.room.roomId, threadId);
shouldSend = false;
}
} else if (!await shouldSendAnyway(commandText)) {
Expand Down
5 changes: 3 additions & 2 deletions src/editor/commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function runSlashCommand(
args: string,
roomId: string,
threadId: string | null,
): Promise<IContent | null> {
): Promise<[content: IContent | null, success: boolean]> {
const result = cmd.run(roomId, threadId, args);
let messageContent: IContent | null = null;
let error = result.error;
Expand Down Expand Up @@ -96,9 +96,10 @@ export async function runSlashCommand(
title: _t(title),
description: errText,
});
return [null, false];
} else {
logger.log("Command success.");
if (messageContent) return messageContent;
return [messageContent, true];
}
}

Expand Down

0 comments on commit 3f99f59

Please sign in to comment.