2019-11-30 13:39:55 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: contact_inboxes
|
|
|
|
#
|
|
|
|
# id :bigint not null, primary key
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# contact_id :bigint
|
|
|
|
# inbox_id :bigint
|
|
|
|
# source_id :string not null
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_contact_inboxes_on_contact_id (contact_id)
|
|
|
|
# index_contact_inboxes_on_inbox_id (inbox_id)
|
|
|
|
# index_contact_inboxes_on_inbox_id_and_source_id (inbox_id,source_id) UNIQUE
|
|
|
|
# index_contact_inboxes_on_source_id (source_id)
|
|
|
|
#
|
|
|
|
# Foreign Keys
|
|
|
|
#
|
|
|
|
# fk_rails_... (contact_id => contacts.id)
|
|
|
|
# fk_rails_... (inbox_id => inboxes.id)
|
|
|
|
#
|
|
|
|
|
2019-10-27 07:44:36 +00:00
|
|
|
class ContactInbox < ApplicationRecord
|
|
|
|
validates :inbox_id, presence: true
|
|
|
|
validates :contact_id, presence: true
|
|
|
|
validates :source_id, presence: true
|
|
|
|
|
|
|
|
belongs_to :contact
|
|
|
|
belongs_to :inbox
|
2020-01-09 07:36:40 +00:00
|
|
|
|
|
|
|
has_many :conversations, dependent: :destroy
|
2020-04-10 11:12:37 +00:00
|
|
|
|
|
|
|
def webhook_data
|
|
|
|
{
|
|
|
|
id: id,
|
|
|
|
contact: contact.try(:webhook_data),
|
|
|
|
inbox: inbox.webhook_data,
|
|
|
|
account: inbox.account.webhook_data,
|
|
|
|
current_conversation: current_conversation.try(:webhook_data),
|
|
|
|
source_id: source_id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_conversation
|
|
|
|
conversations.last
|
|
|
|
end
|
2019-10-27 07:44:36 +00:00
|
|
|
end
|