2019-11-30 13:39:55 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: contacts
|
|
|
|
#
|
2020-02-09 10:17:48 +00:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# additional_attributes :jsonb
|
|
|
|
# email :string
|
|
|
|
# name :string
|
|
|
|
# phone_number :string
|
|
|
|
# pubsub_token :string
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# account_id :integer not null
|
2019-11-30 13:39:55 +00:00
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_contacts_on_account_id (account_id)
|
|
|
|
# index_contacts_on_pubsub_token (pubsub_token) UNIQUE
|
|
|
|
#
|
|
|
|
|
2019-08-14 09:48:44 +00:00
|
|
|
class Contact < ApplicationRecord
|
2019-10-16 22:18:48 +00:00
|
|
|
include Pubsubable
|
2020-01-07 17:29:17 +00:00
|
|
|
include Avatarable
|
2020-02-02 17:04:16 +00:00
|
|
|
include AvailabilityStatusable
|
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
|
|
|
|
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,
|
2020-01-07 17:29:17 +00:00
|
|
|
thumbnail: avatar_url,
|
2019-10-16 21:48:07 +00:00
|
|
|
pubsub_token: pubsub_token
|
2019-08-14 09:48:44 +00:00
|
|
|
}
|
|
|
|
end
|
2020-02-26 04:14:24 +00:00
|
|
|
|
|
|
|
def webhook_data
|
|
|
|
{
|
|
|
|
id: id,
|
|
|
|
name: name
|
|
|
|
}
|
|
|
|
end
|
2019-08-14 09:48:44 +00:00
|
|
|
end
|