fix: removed extra changes
This commit is contained in:
parent
bdc99c7fc0
commit
fcab155c07
1 changed files with 5 additions and 7 deletions
|
@ -12,7 +12,7 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder
|
||||||
@response = response
|
@response = response
|
||||||
@inbox = inbox
|
@inbox = inbox
|
||||||
@outgoing_echo = outgoing_echo
|
@outgoing_echo = outgoing_echo
|
||||||
@sender_id = (@outgoing_echo ? @response.recipient_id : @response.sender_id)
|
@contact_source_id = (@outgoing_echo ? @response.recipient_id : @response.sender_id)
|
||||||
@message_type = (@outgoing_echo ? :outgoing : :incoming)
|
@message_type = (@outgoing_echo ? :outgoing : :incoming)
|
||||||
@attachments = (@response.attachments || [])
|
@attachments = (@response.attachments || [])
|
||||||
end
|
end
|
||||||
|
@ -36,16 +36,14 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder
|
||||||
private
|
private
|
||||||
|
|
||||||
def contact
|
def contact
|
||||||
@contact = @inbox.contact_inboxes.find_by(source_id: @sender_id)&.contact
|
@contact = @inbox.contact_inboxes.find_by(source_id: @contact_source_id)&.contact
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_contact
|
def build_contact
|
||||||
return if contact.present?
|
return if contact.present?
|
||||||
|
|
||||||
@contact = Contact.create!(contact_params.except(:remote_avatar_url))
|
@contact = Contact.create!(contact_params.except(:remote_avatar_url))
|
||||||
@contact_inbox = ContactInbox.find_or_initialize_by(inbox: @inbox, source_id: @sender_id)
|
@contact_inbox = ContactInbox.find_or_create_by!(contact: contact, inbox: @inbox, source_id: @contact_source_id)
|
||||||
@contact_inbox.contact = @contact if @contact_inbox.present? && @contact.present?
|
|
||||||
@contact_inbox.save!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_message
|
def build_message
|
||||||
|
@ -68,7 +66,7 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_conversation
|
def build_conversation
|
||||||
@contact_inbox ||= contact.contact_inboxes.find_by!(source_id: @sender_id)
|
@contact_inbox ||= contact.contact_inboxes.find_by!(source_id: @contact_source_id)
|
||||||
Conversation.create!(conversation_params.merge(
|
Conversation.create!(conversation_params.merge(
|
||||||
contact_inbox_id: @contact_inbox.id
|
contact_inbox_id: @contact_inbox.id
|
||||||
))
|
))
|
||||||
|
@ -122,7 +120,7 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder
|
||||||
def contact_params
|
def contact_params
|
||||||
begin
|
begin
|
||||||
k = Koala::Facebook::API.new(@inbox.channel.page_access_token) if @inbox.facebook?
|
k = Koala::Facebook::API.new(@inbox.channel.page_access_token) if @inbox.facebook?
|
||||||
result = k.get_object(@sender_id) || {}
|
result = k.get_object(@contact_source_id) || {}
|
||||||
rescue Koala::Facebook::AuthenticationError
|
rescue Koala::Facebook::AuthenticationError
|
||||||
@inbox.channel.authorization_error!
|
@inbox.channel.authorization_error!
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Reference in a new issue