From ce8ebbfc2f632f9673cf23545a0ec02d7618853c Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 19 Jul 2020 14:28:32 +0300 Subject: [PATCH] Propagate staff reply edits/deletions to the DB --- src/data/Thread.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/data/Thread.js b/src/data/Thread.js index 84582c3..7046366 100644 --- a/src/data/Thread.js +++ b/src/data/Thread.js @@ -136,8 +136,8 @@ class Thread { } /** - * @param {string} id - * @param {Object} data + * @param {number} id + * @param {object} data * @returns {Promise} * @private */ @@ -147,6 +147,17 @@ class Thread { .update(data); } + /** + * @param {number} id + * @returns {Promise} + * @private + */ + async _deleteThreadMessage(id) { + await knex('thread_messages') + .where('id', id) + .delete(); + } + /** * @returns {string} * @private @@ -561,6 +572,14 @@ class Thread { { isAnonymous: threadMessage.is_anonymous } ); + // FIXME: Fix attachment links disappearing by moving them off the main message content in the DB + const formattedLog = formatters.formatStaffReplyLogMessage( + moderator, + newText, + threadMessage.message_number, + { isAnonymous: threadMessage.is_anonymous } + ); + await bot.editMessage(threadMessage.dm_channel_id, threadMessage.dm_message_id, formattedDM); await bot.editMessage(this.channel_id, threadMessage.inbox_message_id, formattedThreadMessage); @@ -569,6 +588,8 @@ class Thread { const logNotification = formatters.formatStaffReplyEditNotificationLogMessage(moderator, threadMessage, newText); await this.postSystemMessage(threadNotification, null, { logBody: logNotification }); } + + await this._updateThreadMessage(threadMessage.id, { body: formattedLog }); } /** @@ -587,6 +608,8 @@ class Thread { const logNotification = formatters.formatStaffReplyDeletionNotificationLogMessage(moderator, threadMessage); await this.postSystemMessage(threadNotification, null, { logBody: logNotification }); } + + await this._deleteThreadMessage(threadMessage.id); } /**