diff options
author | Maksim Sukharev <antreesy.web@gmail.com> | 2024-07-12 18:58:25 +0200 |
---|---|---|
committer | Maksim Sukharev <antreesy.web@gmail.com> | 2024-07-12 20:01:42 +0200 |
commit | 43d60043edff09c802137efdfeba7183789329a5 (patch) | |
tree | 439a0706b2fde34632a3362b0625bf4b795e0f67 | |
parent | 2b3591b1507991ddfe9133edd445a769dc041ff3 (diff) |
fix(chat): keep message parents in the store after updatefix/12632/bring-back-parents
- fix from e815ef2dd0cd37e8fde5a3f8cff652dc1277970b works for plain values, but we don't propagate grand-parents to parents
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
-rw-r--r-- | src/store/messagesStore.js | 9 | ||||
-rw-r--r-- | src/store/messagesStore.spec.js | 39 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js index 291fbe977..4b6d48617 100644 --- a/src/store/messagesStore.js +++ b/src/store/messagesStore.js @@ -290,7 +290,14 @@ const mutations = { if (!state.messages[token]) { Vue.set(state.messages, token, {}) } - Vue.set(state.messages[token], message.id, message) + // TODO split adding and updating message in the store to different actions + // message.parent doesn't contain grand-parent, so we should keep it + // when updating message in store from new message.parent object + const storedMessage = state.messages[token][message.id] + const preparedMessage = !message.parent && storedMessage?.parent + ? { ...message, parent: storedMessage.parent } + : message + Vue.set(state.messages[token], message.id, preparedMessage) }, /** * Deletes a message from the store. diff --git a/src/store/messagesStore.spec.js b/src/store/messagesStore.spec.js index 7d230381d..a4f893e1b 100644 --- a/src/store/messagesStore.spec.js +++ b/src/store/messagesStore.spec.js @@ -219,6 +219,45 @@ describe('messagesStore', () => { store.dispatch('processMessage', { token: TOKEN, message: message2 }) expect(store.getters.messagesList(TOKEN)).toStrictEqual([message2]) }) + + test('replaces existing message from system message and drops outdated properties, apart from parent', () => { + const message1 = { + id: 2, + token: TOKEN, + message: 'helo-helo', + 'outdated-property': 'outdated-value', + parent: { + id: 1, + token: TOKEN, + message: 'hello', + timestamp: 100, + }, + timestamp: 200, + } + const message2 = { + id: 4, + token: TOKEN, + message: '👍', + messageType: 'system', + systemMessage: 'reaction', + parent: { + id: 2, + token: TOKEN, + message: 'hello-hello', + lastEditTimestamp: 300, + timestamp: 200, + reactions: { '👍': 1 }, + }, + timestamp: 400, + } + + store.dispatch('processMessage', { token: TOKEN, message: message1 }) + store.dispatch('processMessage', { token: TOKEN, message: message2 }) + expect(store.getters.messagesList(TOKEN)).toStrictEqual([{ + ...message2.parent, + parent: message1.parent, + }]) + }) }) test('message list', () => { |