Contact model changes (#184)

* move source id from contacts

* Fix contactInbox model name

* rubocop fix

* Fix rspec
This commit is contained in:
Sojan Jose
2019-10-27 13:14:36 +05:30
committed by GitHub
parent 3b6d58bbdf
commit c21c839dca
12 changed files with 57 additions and 20 deletions

View File

@@ -1,20 +1,22 @@
class Contact < ApplicationRecord
include Pubsubable
validates :account_id, presence: true
validates :inbox_id, presence: true
belongs_to :account
belongs_to :inbox
has_many :conversations, dependent: :destroy
has_many :contact_inboxes, dependent: :destroy
has_many :inboxes, through: :contact_inboxes
mount_uploader :avatar, AvatarUploader
def get_source_id(inbox_id)
contact_inboxes.find_by!(inbox_id: inbox_id).source_id
end
def push_event_data
{
id: id,
name: name,
thumbnail: avatar.thumb.url,
channel: inbox.try(:channel).try(:name),
pubsub_token: pubsub_token
}
end

View File

@@ -0,0 +1,8 @@
class ContactInbox < ApplicationRecord
validates :inbox_id, presence: true
validates :contact_id, presence: true
validates :source_id, presence: true
belongs_to :contact
belongs_to :inbox
end

View File

@@ -6,11 +6,13 @@ class Inbox < ApplicationRecord
belongs_to :account
belongs_to :channel, polymorphic: true, dependent: :destroy
has_many :contact_inboxes, dependent: :destroy
has_many :contacts, through: :contact_inboxes
has_many :inbox_members, dependent: :destroy
has_many :members, through: :inbox_members, source: :user
has_many :conversations, dependent: :destroy
has_many :messages, through: :conversations
has_many :contacts, dependent: :destroy
after_create :subscribe_webhook, if: :facebook?
after_destroy :delete_round_robin_agents