From 92724576afef425a2ed46ee2cb19c5605ea312fd Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Mon, 31 Oct 2022 22:05:48 +0530 Subject: [PATCH] fix: Update conversation read status indicator logic (#5777) --- .../components/widgets/conversation/MessagesView.vue | 2 -- app/javascript/dashboard/helper/actionCable.js | 3 +-- .../dashboard/mixins/specs/conversaton.spec.js | 7 ------- .../dashboard/store/modules/conversations/actions.js | 4 ---- .../dashboard/store/modules/conversations/getters.js | 3 --- .../dashboard/store/modules/conversations/index.js | 4 ---- .../modules/specs/conversations/actions.spec.js | 9 --------- .../modules/specs/conversations/getters.spec.js | 10 ---------- .../modules/specs/conversations/mutations.spec.js | 12 ------------ app/javascript/dashboard/store/mutation-types.js | 1 - 10 files changed, 1 insertion(+), 54 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue b/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue index 5b2d322e3..56a1dcb89 100644 --- a/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue +++ b/app/javascript/dashboard/components/widgets/conversation/MessagesView.vue @@ -139,7 +139,6 @@ export default { listLoadingStatus: 'getAllMessagesLoaded', getUnreadCount: 'getUnreadCount', loadingChatList: 'getChatListLoadingStatus', - conversationLastSeen: 'getConversationLastSeen', }), inboxId() { return this.currentChat.inbox_id; @@ -234,7 +233,6 @@ export default { return 'arrow-chevron-left'; }, getLastSeenAt() { - if (this.conversationLastSeen) return this.conversationLastSeen; const { contact_last_seen_at: contactLastSeenAt } = this.currentChat; return contactLastSeenAt; }, diff --git a/app/javascript/dashboard/helper/actionCable.js b/app/javascript/dashboard/helper/actionCable.js index ba21a3e6a..edf84bee6 100644 --- a/app/javascript/dashboard/helper/actionCable.js +++ b/app/javascript/dashboard/helper/actionCable.js @@ -68,8 +68,7 @@ class ActionCableConnector extends BaseActionCableConnector { }; onConversationRead = data => { - const { contact_last_seen_at: lastSeen } = data; - this.app.$store.dispatch('updateConversationRead', lastSeen); + this.app.$store.dispatch('updateConversation', data); }; onLogout = () => AuthAPI.logout(); diff --git a/app/javascript/dashboard/mixins/specs/conversaton.spec.js b/app/javascript/dashboard/mixins/specs/conversaton.spec.js index a1784afeb..eaa9aab97 100644 --- a/app/javascript/dashboard/mixins/specs/conversaton.spec.js +++ b/app/javascript/dashboard/mixins/specs/conversaton.spec.js @@ -26,11 +26,4 @@ describe('#conversationMixin', () => { conversationMixin.methods.unReadMessages(conversationFixture.conversation) ).toEqual(conversationFixture.unReadMessages); }); - it('should return the user message read flag', () => { - const contactLastSeen = 1649856659; - const createdAt = 1649859419; - expect( - conversationMixin.methods.hasUserReadMessage(createdAt, contactLastSeen) - ).toEqual(false); - }); }); diff --git a/app/javascript/dashboard/store/modules/conversations/actions.js b/app/javascript/dashboard/store/modules/conversations/actions.js index e38f1a7b2..eb13afd4c 100644 --- a/app/javascript/dashboard/store/modules/conversations/actions.js +++ b/app/javascript/dashboard/store/modules/conversations/actions.js @@ -199,10 +199,6 @@ const actions = { } }, - updateConversationRead({ commit }, timestamp) { - commit(types.SET_CONVERSATION_LAST_SEEN, timestamp); - }, - updateMessage({ commit }, message) { commit(types.ADD_MESSAGE, message); }, diff --git a/app/javascript/dashboard/store/modules/conversations/getters.js b/app/javascript/dashboard/store/modules/conversations/getters.js index c5b34af60..75d9aef44 100644 --- a/app/javascript/dashboard/store/modules/conversations/getters.js +++ b/app/javascript/dashboard/store/modules/conversations/getters.js @@ -91,9 +91,6 @@ const getters = { value => value.id === Number(conversationId) ); }, - getConversationLastSeen: _state => { - return _state.conversationLastSeen; - }, }; export default getters; diff --git a/app/javascript/dashboard/store/modules/conversations/index.js b/app/javascript/dashboard/store/modules/conversations/index.js index 8df08089c..bbcafedaf 100644 --- a/app/javascript/dashboard/store/modules/conversations/index.js +++ b/app/javascript/dashboard/store/modules/conversations/index.js @@ -13,7 +13,6 @@ const state = { currentInbox: null, selectedChatId: null, appliedFilters: [], - conversationLastSeen: null, }; // mutations @@ -34,9 +33,6 @@ export const mutations = { _state.allConversations = []; _state.selectedChatId = null; }, - [types.SET_CONVERSATION_LAST_SEEN](_state, timestamp) { - _state.conversationLastSeen = timestamp; - }, [types.SET_ALL_MESSAGES_LOADED](_state) { const [chat] = getSelectedChatConversation(_state); Vue.set(chat, 'allMessagesLoaded', true); diff --git a/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js index 9259a3972..852565230 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/actions.spec.js @@ -380,15 +380,6 @@ describe('#actions', () => { expect(commit.mock.calls).toEqual([[types.CLEAR_CONVERSATION_FILTERS]]); }); }); - - describe('#updateConversationRead', () => { - it('commits the correct mutation and sets the contact_last_seen', () => { - actions.updateConversationRead({ commit }, 1649856659); - expect(commit.mock.calls).toEqual([ - [types.SET_CONVERSATION_LAST_SEEN, 1649856659], - ]); - }); - }); }); describe('#deleteMessage', () => { diff --git a/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js b/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js index ef891deb2..7dc0dade5 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/getters.spec.js @@ -132,16 +132,6 @@ describe('#getters', () => { }); }); - describe('#getConversationLastSeen', () => { - it('getConversationLastSeen', () => { - const timestamp = 1649856659; - const state = { - conversationLastSeen: timestamp, - }; - expect(getters.getConversationLastSeen(state)).toEqual(timestamp); - }); - }); - describe('#getLastEmailInSelectedChat', () => { it('Returns cc in last email', () => { const state = {}; 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 1cba8e973..de0a8907c 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js @@ -200,18 +200,6 @@ describe('#mutations', () => { ]); }); - describe('#SET_CONVERSATION_LAST_SEEN', () => { - it('sets conversation last seen timestamp', () => { - const state = { - conversationLastSeen: null, - }; - - mutations[types.SET_CONVERSATION_LAST_SEEN](state, 1649856659); - - expect(state.conversationLastSeen).toEqual(1649856659); - }); - }); - describe('#UPDATE_CONVERSATION_CUSTOM_ATTRIBUTES', () => { it('update conversation custom attributes', () => { const custom_attributes = { order_id: 1001 }; diff --git a/app/javascript/dashboard/store/mutation-types.js b/app/javascript/dashboard/store/mutation-types.js index bcb6ad9a5..0f801eac9 100755 --- a/app/javascript/dashboard/store/mutation-types.js +++ b/app/javascript/dashboard/store/mutation-types.js @@ -21,7 +21,6 @@ export default { CLEAR_CONTACT_CONVERSATIONS: 'CLEAR_CONTACT_CONVERSATIONS', SET_CONVERSATION_FILTERS: 'SET_CONVERSATION_FILTERS', CLEAR_CONVERSATION_FILTERS: 'CLEAR_CONVERSATION_FILTERS', - SET_CONVERSATION_LAST_SEEN: 'SET_CONVERSATION_LAST_SEEN', SET_CURRENT_CHAT_WINDOW: 'SET_CURRENT_CHAT_WINDOW', CLEAR_CURRENT_CHAT_WINDOW: 'CLEAR_CURRENT_CHAT_WINDOW',