Files
leadchat/app/jobs/conversations/update_message_status_job.rb
Vishnu Narayanan 6b8dd3c86a chore: move UpdateMessageStatus to deferred queue (#11943)
-  move `UpdateMessageStatus` to `deferred` queue below `scheduled_jobs`

---------

Co-authored-by: Pranav <pranav@chatwoot.com>
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
2025-07-16 08:19:00 +05:30

22 lines
819 B
Ruby

class Conversations::UpdateMessageStatusJob < ApplicationJob
queue_as :deferred
# This job only support marking messages as read or delivered, update this array if we want to support more statuses
VALID_STATUSES = %w[read delivered].freeze
def perform(conversation_id, timestamp, status = :read)
return unless VALID_STATUSES.include?(status.to_s)
conversation = Conversation.find_by(id: conversation_id)
return unless conversation
# Mark every message created before the user's viewing time read or delivered
conversation.messages.where(status: %w[sent delivered])
.where.not(message_type: 'incoming')
.where('messages.created_at <= ?', timestamp).find_each do |message|
Messages::StatusUpdateService.new(message, status).perform
end
end
end