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

Commit 3f99f59

Browse files
authored
Keep draft in composer when a slash command syntax errors (#8811)
1 parent 4171c00 commit 3f99f59

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/components/views/rooms/EditMessageComposer.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,14 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
332332
const [cmd, args, commandText] = getSlashCommand(this.model);
333333
if (cmd) {
334334
const threadId = editedEvent?.getThread()?.id || null;
335+
const [content, commandSuccessful] = await runSlashCommand(cmd, args, roomId, threadId);
336+
if (!commandSuccessful) {
337+
return; // errored
338+
}
339+
335340
if (cmd.category === CommandCategories.messages) {
336-
editContent["m.new_content"] = await runSlashCommand(cmd, args, roomId, threadId);
337-
if (!editContent["m.new_content"]) {
338-
return; // errored
339-
}
341+
editContent["m.new_content"] = content;
340342
} else {
341-
runSlashCommand(cmd, args, roomId, threadId);
342343
shouldSend = false;
343344
}
344345
} else if (!await shouldSendAnyway(commandText)) {

src/components/views/rooms/SendMessageComposer.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,12 +351,13 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
351351
? this.props.relation?.event_id
352352
: null;
353353

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

360+
if (cmd.category === CommandCategories.messages) {
360361
attachRelation(content, this.props.relation);
361362
if (replyToEvent) {
362363
addReplyToMessageContent(content, replyToEvent, {
@@ -365,7 +366,6 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
365366
});
366367
}
367368
} else {
368-
runSlashCommand(cmd, args, this.props.room.roomId, threadId);
369369
shouldSend = false;
370370
}
371371
} else if (!await shouldSendAnyway(commandText)) {

src/editor/commands.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function runSlashCommand(
5959
args: string,
6060
roomId: string,
6161
threadId: string | null,
62-
): Promise<IContent | null> {
62+
): Promise<[content: IContent | null, success: boolean]> {
6363
const result = cmd.run(roomId, threadId, args);
6464
let messageContent: IContent | null = null;
6565
let error = result.error;
@@ -96,9 +96,10 @@ export async function runSlashCommand(
9696
title: _t(title),
9797
description: errText,
9898
});
99+
return [null, false];
99100
} else {
100101
logger.log("Command success.");
101-
if (messageContent) return messageContent;
102+
return [messageContent, true];
102103
}
103104
}
104105

0 commit comments

Comments
 (0)