Add more safeguards when using Thread#_postToThreadChannel()

cshd
Dragory 2020-07-14 01:35:26 +03:00
parent 662c6b0c21
commit ec3a2455e0
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
1 changed files with 13 additions and 11 deletions

View File

@ -210,7 +210,7 @@ class Thread {
// Show the reply in the inbox thread // Show the reply in the inbox thread
const inboxContent = formatters.formatStaffReplyThreadMessage(moderator, text, threadMessage.message_number, { isAnonymous }); const inboxContent = formatters.formatStaffReplyThreadMessage(moderator, text, threadMessage.message_number, { isAnonymous });
const inboxMessage = await this._postToThreadChannel(inboxContent, files); 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 // Interrupt scheduled closing, if in progress
if (this.scheduled_close_at) { if (this.scheduled_close_at) {
@ -288,16 +288,18 @@ class Thread {
* @param {*} args * @param {*} args
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async postSystemMessage(content, ...args) { async postSystemMessage(content, file = null) {
const msg = await this._postToThreadChannel(content, ...args); const msg = await this._postToThreadChannel(content, file);
await this._addThreadMessageToDB({ if (msg) {
message_type: THREAD_MESSAGE_TYPE.SYSTEM, await this._addThreadMessageToDB({
user_id: null, message_type: THREAD_MESSAGE_TYPE.SYSTEM,
user_name: '', user_id: null,
body: typeof content === 'string' ? content : content.content, user_name: '',
is_anonymous: 0, body: typeof content === 'string' ? content : content.content,
dm_message_id: msg.id is_anonymous: 0,
}); dm_message_id: msg.id
});
}
} }
/** /**