chore: Update MarkMessagesAsReadJob to accept delivered status (#8319)
This commit is contained in:
@@ -28,7 +28,7 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController
|
||||
|
||||
conversation.contact_last_seen_at = DateTime.now.utc
|
||||
conversation.save!
|
||||
::Conversations::MarkMessagesAsReadJob.perform_later(conversation.id, conversation.contact_last_seen_at)
|
||||
::Conversations::UpdateMessageStatusJob.perform_later(conversation.id, conversation.contact_last_seen_at)
|
||||
head :ok
|
||||
end
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class Public::Api::V1::Inboxes::ConversationsController < Public::Api::V1::Inbox
|
||||
def update_last_seen
|
||||
@conversation.contact_last_seen_at = DateTime.now.utc
|
||||
@conversation.save!
|
||||
::Conversations::MarkMessagesAsReadJob.perform_later(@conversation.id, @conversation.contact_last_seen_at)
|
||||
::Conversations::UpdateMessageStatusJob.perform_later(@conversation.id, @conversation.contact_last_seen_at)
|
||||
head :ok
|
||||
end
|
||||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
class Conversations::MarkMessagesAsReadJob < ApplicationJob
|
||||
queue_as :low
|
||||
|
||||
def perform(conversation_id, timestamp)
|
||||
conversation = Conversation.find_by(id: conversation_id)
|
||||
|
||||
return unless conversation
|
||||
|
||||
# Mark every message created before the user's viewing time as read.
|
||||
conversation.messages.where(status: %w[sent delivered])
|
||||
.where.not(message_type: 'incoming')
|
||||
.where('messages.created_at <= ?', timestamp).find_each do |message|
|
||||
message.update!(status: 'read')
|
||||
end
|
||||
end
|
||||
end
|
||||
21
app/jobs/conversations/update_message_status_job.rb
Normal file
21
app/jobs/conversations/update_message_status_job.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class Conversations::UpdateMessageStatusJob < ApplicationJob
|
||||
queue_as :low
|
||||
|
||||
# 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|
|
||||
message.update!(status: status)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,7 +4,7 @@ class Instagram::ReadStatusService
|
||||
def perform
|
||||
return if instagram_channel.blank?
|
||||
|
||||
::Conversations::MarkMessagesAsReadJob.perform_later(message.conversation.id, message.created_at) if message.present?
|
||||
::Conversations::UpdateMessageStatusJob.perform_later(message.conversation.id, message.created_at) if message.present?
|
||||
end
|
||||
|
||||
def instagram_id
|
||||
|
||||
Reference in New Issue
Block a user