From 69bed3e08da614d8e81f12654feed116facdae7f Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Fri, 30 Dec 2022 13:13:33 -0800 Subject: [PATCH] fix: Update unread_messages count in WhatsApp inboxes (#6154) * fix: Update unread_count from backend instead of computing on the frontend * Fix spec * Remove status indicator on private notifications * CodeClimate fix * CodeClimate --- .../components/widgets/conversation/bubble/Actions.vue | 2 +- .../dashboard/store/modules/conversations/index.js | 2 ++ .../store/modules/specs/conversations/mutations.spec.js | 2 ++ app/models/message.rb | 5 ++++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/bubble/Actions.vue b/app/javascript/dashboard/components/widgets/conversation/bubble/Actions.vue index d5423929b..e330d7f33 100644 --- a/app/javascript/dashboard/components/widgets/conversation/bubble/Actions.vue +++ b/app/javascript/dashboard/components/widgets/conversation/bubble/Actions.vue @@ -186,7 +186,7 @@ export default { return `https://www.instagram.com/stories/${storySender}/${storyId}`; }, showStatusIndicators() { - if ((this.isOutgoing || this.isTemplate) && !this.private) { + if ((this.isOutgoing || this.isTemplate) && !this.isPrivate) { return true; } return false; diff --git a/app/javascript/dashboard/store/modules/conversations/index.js b/app/javascript/dashboard/store/modules/conversations/index.js index b3c9ab7e4..a8a2fdabe 100644 --- a/app/javascript/dashboard/store/modules/conversations/index.js +++ b/app/javascript/dashboard/store/modules/conversations/index.js @@ -108,6 +108,8 @@ export const mutations = { } else { chat.messages.push(message); chat.timestamp = message.created_at; + const { conversation: { unread_count: unreadCount = 0 } = {} } = message; + chat.unread_count = unreadCount; if (selectedChatId === conversationId) { window.bus.$emit(BUS_EVENTS.SCROLL_TO_MESSAGE); } 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 caa9df090..738de5c55 100644 --- a/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js +++ b/app/javascript/dashboard/store/modules/specs/conversations/mutations.spec.js @@ -103,6 +103,7 @@ describe('#mutations', () => { created_at: 1602256198, }, ], + unread_count: 0, timestamp: 1602256198, }, ]); @@ -130,6 +131,7 @@ describe('#mutations', () => { created_at: 1602256198, }, ], + unread_count: 0, timestamp: 1602256198, }, ]); diff --git a/app/models/message.rb b/app/models/message.rb index 2c8827b12..5ff749f6b 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -104,7 +104,10 @@ class Message < ApplicationRecord created_at: created_at.to_i, message_type: message_type_before_type_cast, conversation_id: conversation.display_id, - conversation: { assignee_id: conversation.assignee_id } + conversation: { + assignee_id: conversation.assignee_id, + unread_count: conversation.unread_incoming_messages.count + } ) data.merge!(echo_id: echo_id) if echo_id.present? validate_instagram_story if instagram_story_mention?