From ec3a2455e0623064a8b6ff558137397e6a6a94fe Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Tue, 14 Jul 2020 01:35:26 +0300 Subject: [PATCH] Add more safeguards when using Thread#_postToThreadChannel() --- src/data/Thread.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/data/Thread.js b/src/data/Thread.js index 13501fe..1db3bc1 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -210,7 +210,7 @@ class Thread { // Show the reply in the inbox thread const inboxContent = formatters.formatStaffReplyThreadMessage(moderator, text, threadMessage.message_number, { isAnonymous }); const inboxMessage = await this._postToThreadChannel(inboxContent, files); - await this._updateThreadMessage(threadMessage.id, { inbox_message_id: inboxMessage.id }); + if (inboxMessage) await this._updateThreadMessage(threadMessage.id, { inbox_message_id: inboxMessage.id }); // Interrupt scheduled closing, if in progress if (this.scheduled_close_at) { @@ -288,16 +288,18 @@ class Thread { * @param {*} args * @returns {Promise} */ - async postSystemMessage(content, ...args) { - const msg = await this._postToThreadChannel(content, ...args); - await this._addThreadMessageToDB({ - message_type: THREAD_MESSAGE_TYPE.SYSTEM, - user_id: null, - user_name: '', - body: typeof content === 'string' ? content : content.content, - is_anonymous: 0, - dm_message_id: msg.id - }); + async postSystemMessage(content, file = null) { + const msg = await this._postToThreadChannel(content, file); + if (msg) { + await this._addThreadMessageToDB({ + message_type: THREAD_MESSAGE_TYPE.SYSTEM, + user_id: null, + user_name: '', + body: typeof content === 'string' ? content : content.content, + is_anonymous: 0, + dm_message_id: msg.id + }); + } } /**