chore: Refactor MarkMessagesAsReadJob based on conversation id and time stamp (#8217)

- Mark all messages as read by providing the conversation ID and timestamp.
- For Instagram, ensure all previous messages that weren't marked as failed are now marked as read. This is because the read events are only triggered for the most recent message and not for any previous ones.
This commit is contained in:
Muhsin Keloth
2023-10-28 03:51:39 +05:30
committed by GitHub
parent 61e03fa33a
commit 24fbab94c3
8 changed files with 36 additions and 24 deletions

View File

@@ -17,7 +17,11 @@ describe Instagram::ReadStatusService do
context 'when messaging_seen callback is fired' do
let(:message) { conversation.messages.last }
it 'updates the message status to read if the status is delivered' do
before do
allow(Conversations::MarkMessagesAsReadJob).to receive(:perform_later)
end
it 'enqueues the MarkMessagesAsReadJob with correct parameters if the message is found' do
params = {
recipient: {
id: 'chatwoot-app-user-id-1'
@@ -27,10 +31,10 @@ describe Instagram::ReadStatusService do
}
}
described_class.new(params: params).perform
expect(conversation.reload.messages.last.status).to eq('read')
expect(Conversations::MarkMessagesAsReadJob).to have_received(:perform_later).with(conversation.id, message.created_at)
end
it 'does not update the status if message is not found' do
it 'does not enqueue the MarkMessagesAsReadJob if the message is not found' do
params = {
recipient: {
id: 'chatwoot-app-user-id-1'
@@ -39,9 +43,8 @@ describe Instagram::ReadStatusService do
mid: 'random-message-id'
}
}
described_class.new(params: params).perform
expect(conversation.reload.messages.last.status).not_to eq('read')
expect(Conversations::MarkMessagesAsReadJob).not_to have_received(:perform_later)
end
end
end