From 96fa3b75d86ad52b71a65aedb6b2142dc865aa8d Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Fri, 23 Feb 2024 16:29:12 +0100 Subject: [PATCH] fix(messagesStore): don't update parent message in the store, if it hasn't been unchanged Signed-off-by: Maksim Sukharev --- src/store/messagesStore.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js index 4d4d25924fe..84bed312bf7 100644 --- a/src/store/messagesStore.js +++ b/src/store/messagesStore.js @@ -516,8 +516,7 @@ const actions = { /** * Adds message to the store. * - * If the message has a parent message object, - * first it adds the parent to the store. + * If the message has a parent message presented in the store, updates it as well. * * @param {object} context default store context; * @param {object} payload payload; @@ -533,9 +532,9 @@ const actions = { || message.systemMessage === 'reaction_deleted' || message.systemMessage === 'reaction_revoked' || message.systemMessage === 'message_edited')) { - // If parent message is presented in store already, we update it + // If parent message is presented in store and is different, we update it const parentInStore = context.getters.message(token, message.parent.id) - if (Object.keys(parentInStore).length !== 0) { + if (Object.keys(parentInStore).length !== 0 && JSON.stringify(parentInStore) !== JSON.stringify(message.parent)) { context.commit('addMessage', { token, message: message.parent }) if (message.systemMessage === 'message_edited') { EventBus.$emit('message-edited') @@ -553,7 +552,7 @@ const actions = { // Check existing messages for having a deleted message as parent, and update them if (message.systemMessage === 'message_deleted') { context.getters.messagesList(token) - .filter(storedMessage => storedMessage.parent?.id === message.parent.id) + .filter(storedMessage => storedMessage.parent?.id === message.parent.id && JSON.stringify(storedMessage.parent) !== JSON.stringify(message.parent)) .forEach(storedMessage => { context.commit('addMessage', { token, message: Object.assign({}, storedMessage, { parent: message.parent }) }) })