From 8ff45bcd605cb6bb7fc2f57b8c7bb878abef450a Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Tue, 11 Mar 2025 09:36:18 +0530 Subject: [PATCH] feat: ignore out of sync messages --- .../store/modules/conversations/index.js | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/app/javascript/dashboard/store/modules/conversations/index.js b/app/javascript/dashboard/store/modules/conversations/index.js index 1d7fdbe46..520421ae6 100644 --- a/app/javascript/dashboard/store/modules/conversations/index.js +++ b/app/javascript/dashboard/store/modules/conversations/index.js @@ -6,6 +6,7 @@ import { MESSAGE_STATUS } from 'shared/constants/messages'; import wootConstants from 'dashboard/constants/globals'; import { BUS_EVENTS } from '../../../../shared/constants/busEvents'; import { emitter } from 'shared/helpers/mitt'; +import * as Sentry from '@sentry/vue'; const state = { allConversations: [], @@ -209,16 +210,24 @@ export const mutations = { [types.UPDATE_CONVERSATION](_state, conversation) { const { allConversations } = _state; - const currentConversationIndex = allConversations.findIndex( - c => c.id === conversation.id - ); - if (currentConversationIndex > -1) { - const { messages, ...conversationAttributes } = conversation; - const currentConversation = { - ...allConversations[currentConversationIndex], - ...conversationAttributes, - }; - allConversations[currentConversationIndex] = currentConversation; + const index = allConversations.findIndex(c => c.id === conversation.id); + + if (index > -1) { + const selectedConversation = allConversations[index]; + + // ignore out of order events + if (conversation.updated_at <= selectedConversation.updated_at) { + Sentry.withScope(scope => { + scope.setContext('incoming', conversation); + scope.setContext('stored', selectedConversation); + Sentry.captureMessage('Conversation update mismatch'); + }); + + return; + } + + const { messages, ...updates } = conversation; + allConversations[index] = { ...selectedConversation, ...updates }; if (_state.selectedChatId === conversation.id) { emitter.emit(BUS_EVENTS.FETCH_LABEL_SUGGESTIONS); emitter.emit(BUS_EVENTS.SCROLL_TO_MESSAGE);