fix: Contact Inbox uniq index violation

This commit is contained in:
tejaswini chile 2022-09-27 20:32:14 +05:30
parent 83eee7df91
commit dc4cc538c8

View file

@ -36,14 +36,15 @@ class Messages::Facebook::MessageBuilder < Messages::Messenger::MessageBuilder
private
def contact
@contact ||= @inbox.contact_inboxes.find_by(source_id: @sender_id)&.contact
@contact = @inbox.contact_inboxes.find_by(source_id: @sender_id)&.contact
end
def build_contact
return if contact.present?
@contact = Contact.create!(contact_params.except(:remote_avatar_url))
@contact_inbox = ContactInbox.find_or_create_by!(contact: contact, inbox: @inbox, source_id: @sender_id)
@contact_inbox = ContactInbox.find_or_create_by!(inbox: @inbox, source_id: @sender_id)
@contact_inbox.update(contact: contact) if @contact_inbox.present? && @contact.present?
end
def build_message