fix: Update unread_count being 0 if agent has not seen the conversation (#7690)

This commit is contained in:
Pranav Raj S
2023-08-07 18:50:31 -07:00
committed by GitHub
parent 1c8f41f387
commit 4baa4363f4
2 changed files with 8 additions and 2 deletions

View File

@@ -166,11 +166,11 @@ class Conversation < ApplicationRecord
end
def unread_messages
messages.created_since(agent_last_seen_at)
agent_last_seen_at.present? ? messages.created_since(agent_last_seen_at) : messages
end
def unread_incoming_messages
messages.incoming.created_since(agent_last_seen_at)
unread_messages.incoming
end
def push_event_data

View File

@@ -497,6 +497,12 @@ RSpec.describe Conversation do
it 'returns unread incoming messages' do
expect(unread_incoming_messages).to contain_exactly(message)
end
it 'returns unread incoming messages even if the agent has not seen the conversation' do
conversation.update!(agent_last_seen_at: nil)
expect(unread_incoming_messages).to contain_exactly(message)
end
end
describe '#push_event_data' do