Module: TurboChat::ModelExtensions::ChatParticipant::ClassMethods

Defined in:
lib/turbo_chat/model_extensions/chat_participant.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_chat_participantObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/turbo_chat/model_extensions/chat_participant.rb', line 5

def acts_as_chat_participant
  return if reflect_on_association(:chat_memberships).present?

  has_many :chat_memberships,
           -> { order(created_at: :asc, id: :asc) },
           as: :participant,
           class_name: "TurboChat::ChatMembership",
           dependent: :destroy

  has_many :chat_messages,
           -> { order(created_at: :asc, id: :asc) },
           as: :participant,
           class_name: "TurboChat::ChatMessage",
           dependent: :destroy

  has_many :chats,
           -> { distinct },
           through: :chat_memberships,
           source: :chat,
           class_name: "TurboChat::Chat"

  include TurboChat::ModelExtensions::ChatParticipant::InstanceMethods
end