2019-08-14 09:48:44 +00:00
|
|
|
class Contact < ApplicationRecord
|
2019-10-16 22:18:48 +00:00
|
|
|
include Pubsubable
|
2019-08-14 09:48:44 +00:00
|
|
|
validates :account_id, presence: true
|
|
|
|
|
|
|
|
belongs_to :account
|
2019-10-20 19:10:18 +00:00
|
|
|
has_many :conversations, dependent: :destroy
|
2019-10-27 07:44:36 +00:00
|
|
|
has_many :contact_inboxes, dependent: :destroy
|
|
|
|
has_many :inboxes, through: :contact_inboxes
|
2019-08-14 09:48:44 +00:00
|
|
|
mount_uploader :avatar, AvatarUploader
|
|
|
|
|
2019-10-27 07:44:36 +00:00
|
|
|
def get_source_id(inbox_id)
|
|
|
|
contact_inboxes.find_by!(inbox_id: inbox_id).source_id
|
|
|
|
end
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
def push_event_data
|
|
|
|
{
|
|
|
|
id: id,
|
|
|
|
name: name,
|
|
|
|
thumbnail: avatar.thumb.url,
|
2019-10-16 21:48:07 +00:00
|
|
|
pubsub_token: pubsub_token
|
2019-08-14 09:48:44 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|