mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 05:33:41 +08:00
abcaa1a961
This is a followup of the previous refactor where we created two new models to handle all the dedicated logic that was present in the `ChatChannel` model. For the sake of consistency, `DMChannel` has been renamed to `DirectMessageChannel` and the previous `DirectMessageChannel` model is now named `DirectMessage`. This should help reasoning about direct messages.
20 lines
362 B
Ruby
20 lines
362 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Chatable
|
|
extend ActiveSupport::Concern
|
|
|
|
def chat_channel
|
|
channel_class.new(chatable: self)
|
|
end
|
|
|
|
def create_chat_channel!(**args)
|
|
channel_class.create!(args.merge(chatable: self))
|
|
end
|
|
|
|
private
|
|
|
|
def channel_class
|
|
"#{self.class}Channel".safe_constantize || raise("Unknown chatable #{self}")
|
|
end
|
|
end
|