2019-10-16 06:52:30 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
class Integrations::Facebook::DeliveryStatus
|
|
|
|
def initialize(params)
|
|
|
|
@params = params
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def perform
|
|
|
|
update_message_status
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
private
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def sender_id
|
|
|
|
@params.sender['id']
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def contact
|
2020-08-30 07:06:21 +00:00
|
|
|
::ContactInbox.find_by(source_id: sender_id)&.contact
|
2020-01-09 07:36:40 +00:00
|
|
|
end
|
2019-08-31 06:22:09 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def conversation
|
2020-08-30 07:06:21 +00:00
|
|
|
@conversation ||= ::Conversation.find_by(contact_id: contact.id) if contact.present?
|
2020-01-09 07:36:40 +00:00
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
def update_message_status
|
2020-08-30 07:06:21 +00:00
|
|
|
return unless conversation
|
|
|
|
|
2020-01-09 07:36:40 +00:00
|
|
|
conversation.user_last_seen_at = @params.at
|
|
|
|
conversation.save!
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|
|
|
|
end
|