mirror of
https://github.com/discourse/discourse.git
synced 2025-02-12 06:56:28 +08:00
![Martin Brennan](/assets/img/avatar_default.png)
This commit moves the category channel creation out of the Chat::Api::Channel controller and into a dedicated CreateCategoryChannel service. A follow up commit will move the DM channel creation out of the old DirectMessageChannelCreator service. Also includes a new on_model_errors helper for chat service class usage, that collects model validation errors to present in a nice way. --------- Co-authored-by: Loïc Guitaut <loic@discourse.org>
33 lines
616 B
Ruby
33 lines
616 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Chat
|
|
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
|
|
|
|
def create_chat_channel(**args)
|
|
channel_class.create(args.merge(chatable: self))
|
|
end
|
|
|
|
private
|
|
|
|
def channel_class
|
|
case self
|
|
when Chat::DirectMessage
|
|
Chat::DirectMessageChannel
|
|
when Category
|
|
Chat::CategoryChannel
|
|
else
|
|
raise("Unknown chatable #{self}")
|
|
end
|
|
end
|
|
end
|
|
end
|