Contact model changes (#184)
* move source id from contacts * Fix contactInbox model name * rubocop fix * Fix rspec
This commit is contained in:
@@ -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
|
||||
|
||||
8
app/models/contact_inbox.rb
Normal file
8
app/models/contact_inbox.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user