diff --git a/app/javascript/dashboard/store/modules/conversations/index.js b/app/javascript/dashboard/store/modules/conversations/index.js index 84be116fe..d7137694e 100644 --- a/app/javascript/dashboard/store/modules/conversations/index.js +++ b/app/javascript/dashboard/store/modules/conversations/index.js @@ -228,7 +228,10 @@ export const mutations = { }, [types.ADD_CONVERSATION](_state, conversation) { - _state.allConversations.push(conversation); + const exists = _state.allConversations.some(c => c.id === conversation.id); + if (!exists) { + _state.allConversations.push(conversation); + } }, [types.DELETE_CONVERSATION](_state, conversationId) { diff --git a/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js index 01abf05f7..bd048dbba 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js @@ -975,6 +975,16 @@ describe('#mutations', () => { mutations[types.ADD_CONVERSATION](state, conversation); expect(state.allConversations).toEqual([conversation]); }); + + it('should not add a duplicate conversation', () => { + const conversation = { id: 1, messages: [] }; + const state = { + allConversations: [conversation], + }; + + mutations[types.ADD_CONVERSATION](state, { id: 1, messages: [] }); + expect(state.allConversations).toHaveLength(1); + }); }); describe('#DELETE_CONVERSATION', () => {