From 5761120fa8d160b1f2f6d062d73905adae375c1f Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 29 Jun 2023 19:08:43 +0530 Subject: [PATCH] feat: add unread count calculation in meta --- app/finders/conversation_finder.rb | 10 +++++++--- .../api/v1/accounts/conversations/index.json.jbuilder | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/finders/conversation_finder.rb b/app/finders/conversation_finder.rb index cbbd60caa..622fa04ed 100644 --- a/app/finders/conversation_finder.rb +++ b/app/finders/conversation_finder.rb @@ -30,7 +30,7 @@ class ConversationFinder def perform set_up - mine_count, unassigned_count, all_count, = set_count_for_all_conversations + mine_count, unassigned_count, all_count, unread_count = set_count_for_all_conversations assigned_count = all_count - unassigned_count filter_by_assignee_type @@ -41,7 +41,8 @@ class ConversationFinder mine_count: mine_count, assigned_count: assigned_count, unassigned_count: unassigned_count, - all_count: all_count + all_count: all_count, + unread_count: unread_count } } end @@ -147,7 +148,10 @@ class ConversationFinder [ @conversations.assigned_to(current_user).count, @conversations.unassigned.count, - @conversations.count + @conversations.count, + @conversations.joins(:messages) + .where('conversations.agent_last_seen_at IS NULL OR messages.created_at > conversations.agent_last_seen_at') + .distinct.count ] end diff --git a/app/views/api/v1/accounts/conversations/index.json.jbuilder b/app/views/api/v1/accounts/conversations/index.json.jbuilder index 670899f38..0d084a9b0 100644 --- a/app/views/api/v1/accounts/conversations/index.json.jbuilder +++ b/app/views/api/v1/accounts/conversations/index.json.jbuilder @@ -4,6 +4,7 @@ json.data do json.assigned_count @conversations_count[:assigned_count] json.unassigned_count @conversations_count[:unassigned_count] json.all_count @conversations_count[:all_count] + json.unread_count @conversations_count[:unread_count] end json.payload do json.array! @conversations do |conversation|