diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel.js b/plugins/chat/assets/javascripts/discourse/components/chat-channel.js index 3901de6a369..7128d0e9936 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-channel.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel.js @@ -724,28 +724,24 @@ export default class ChatLivePane extends Component { this.scrollToLatestMessage(); } - return this.chatApi - .sendMessage(this.args.channel.id, { + try { + await this.chatApi.sendMessage(this.args.channel.id, { message: message.message, in_reply_to_id: message.inReplyTo?.id, staged_id: message.id, upload_ids: message.uploads.map((upload) => upload.id), - }) - .then(() => { - this.scrollToLatestMessage(); - }) - .catch((error) => { - this._onSendError(message.id, error); - this.scrollToBottom(); - }) - .finally(() => { - if (this._selfDeleted) { - return; - } + }); + this.scrollToLatestMessage(); + } catch (error) { + this._onSendError(message.id, error); + this.scrollToBottom(); + } finally { + if (!this._selfDeleted) { this.chatDraftsManager.remove({ channelId: this.args.channel.id }); this.chatChannelPane.sending = false; - }); + } + } } async _upsertChannelWithMessage(channel, data) { diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.js b/plugins/chat/assets/javascripts/discourse/components/chat-thread.js index 3b514c94797..64dcab18d49 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.js +++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.js @@ -250,8 +250,8 @@ export default class ChatThreadPanel extends Component { this.scrollToBottom(); - return this.chatApi - .sendMessage(this.channel.id, { + try { + await this.chatApi.sendMessage(this.channel.id, { message: message.message, in_reply_to_id: message.thread.staged ? message.thread.originalMessage.id @@ -260,16 +260,14 @@ export default class ChatThreadPanel extends Component { upload_ids: message.uploads.map((upload) => upload.id), thread_id: message.thread.staged ? null : message.thread.id, staged_thread_id: message.thread.staged ? message.thread.id : null, - }) - .catch((error) => { - this.#onSendError(message.id, error); - }) - .finally(() => { - if (this._selfDeleted) { - return; - } - this.chatChannelThreadPane.sending = false; }); + } catch (error) { + this.#onSendError(message.id, error); + } finally { + if (!this._selfDeleted) { + this.chatChannelThreadPane.sending = false; + } + } } async #sendEditMessage(message) {