Chatwoot/app/models/contact.rb
Pranav Raj Sreepuram 2a34255e0b Initial Commit
Co-authored-by: Subin <subinthattaparambil@gmail.com>
Co-authored-by: Manoj <manojmj92@gmail.com>
Co-authored-by: Nithin <webofnithin@gmail.com>
2019-08-14 15:18:44 +05:30

28 lines
628 B
Ruby

class Contact < ApplicationRecord
validates :account_id, presence: true
validates :inbox_id, presence: true
belongs_to :account
belongs_to :inbox
has_many :conversations, dependent: :destroy, foreign_key: :sender_id
mount_uploader :avatar, AvatarUploader
before_create :set_channel
def push_event_data
{
id: id,
name: name,
thumbnail: avatar.thumb.url,
channel: inbox.try(:channel).try(:name),
chat_channel: chat_channel
}
end
def set_channel
begin
self.chat_channel = SecureRandom.hex
end while self.class.exists?(chat_channel: chat_channel)
end
end