Initial Commit
Co-authored-by: Subin <subinthattaparambil@gmail.com> Co-authored-by: Manoj <manojmj92@gmail.com> Co-authored-by: Nithin <webofnithin@gmail.com>
This commit is contained in:
28
app/models/contact.rb
Normal file
28
app/models/contact.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
Reference in New Issue
Block a user