fix: classify bot-owned conversations as assigned

This commit is contained in:
Sojan Jose
2026-07-07 19:52:11 -07:00
parent d96415c814
commit 365935c440
3 changed files with 19 additions and 11 deletions
+1 -1
View File
@@ -189,7 +189,7 @@ class ConversationFinder
counts = @conversations.unscope(:order).pick(
Arel.sql("COUNT(*) FILTER (WHERE assignee_id = #{current_user.id})"),
Arel.sql('COUNT(*) FILTER (WHERE assignee_id IS NULL)'),
Arel.sql('COUNT(*) FILTER (WHERE assignee_id IS NULL AND assignee_agent_bot_id IS NULL)'),
Arel.sql('COUNT(*)')
)
counts || [0, 0, 0]
+2 -2
View File
@@ -75,8 +75,8 @@ class Conversation < ApplicationRecord
enum status: { open: 0, resolved: 1, pending: 2, snoozed: 3 }
enum priority: { low: 0, medium: 1, high: 2, urgent: 3 }
scope :unassigned, -> { where(assignee_id: nil) }
scope :assigned, -> { where.not(assignee_id: nil) }
scope :unassigned, -> { where(assignee_id: nil, assignee_agent_bot_id: nil) }
scope :assigned, -> { where.not(assignee_id: nil).or(where.not(assignee_agent_bot_id: nil)) }
scope :assigned_to, ->(agent) { where(assignee_id: agent.id) }
scope :sort_on_unread, lambda { |_direction|
order(unread_messages_count_arel.desc).sort_on_last_activity_at('desc')
+16 -8
View File
@@ -10,6 +10,8 @@ describe ConversationFinder do
let!(:inbox) { create(:inbox, account: account, enable_auto_assignment: false) }
let!(:contact_inbox) { create(:contact_inbox, inbox: inbox, source_id: 'testing_source_id') }
let!(:restricted_inbox) { create(:inbox, account: account) }
let!(:agent_bot) { create(:agent_bot, account: account) }
let!(:bot_owned_conversation) { create(:conversation, account: account, inbox: inbox, assignee_agent_bot: agent_bot) }
before do
create(:inbox_member, user: user_1, inbox: inbox)
@@ -74,7 +76,7 @@ describe ConversationFinder do
it 'filter conversations by assignee type all' do
result = conversation_finder.perform
expect(result[:conversations].length).to be 4
expect(result[:conversations].length).to be 5
end
end
@@ -83,7 +85,10 @@ describe ConversationFinder do
it 'filter conversations by assignee type unassigned' do
result = conversation_finder.perform
conversation_ids = result[:conversations].map(&:id)
expect(result[:conversations].length).to be 1
expect(conversation_ids).not_to include(bot_owned_conversation.id)
end
end
@@ -92,7 +97,7 @@ describe ConversationFinder do
it 'returns all conversations' do
result = conversation_finder.perform
expect(result[:conversations].length).to be 5
expect(result[:conversations].length).to be 6
end
end
@@ -162,16 +167,19 @@ describe ConversationFinder do
it 'filter conversations by assignee type assigned' do
result = conversation_finder.perform
expect(result[:conversations].length).to be 3
conversation_ids = result[:conversations].map(&:id)
expect(result[:conversations].length).to be 4
expect(conversation_ids).to include(bot_owned_conversation.id)
end
it 'returns the correct meta' do
result = conversation_finder.perform
expect(result[:count]).to eq({
mine_count: 2,
assigned_count: 3,
assigned_count: 4,
unassigned_count: 1,
all_count: 4
all_count: 5
})
end
end
@@ -213,7 +221,7 @@ describe ConversationFinder do
it 'returns conversations with any source' do
result = conversation_finder.perform
expect(result[:conversations].length).to be 4
expect(result[:conversations].length).to be 5
end
end
@@ -264,9 +272,9 @@ describe ConversationFinder do
result = conversation_finder.perform_meta_only
expect(result[:count]).to eq({
mine_count: 2,
assigned_count: 3,
assigned_count: 4,
unassigned_count: 1,
all_count: 4
all_count: 5
})
end