discourse/plugins/chat/lib/chat_seeder.rb
Roman Rizzi 0a5f548635
DEV: Move discourse-chat to the core repo. (#18776)
As part of this move, we are also renaming `discourse-chat` to `chat`.
2022-11-02 10:41:30 -03:00

29 lines
846 B
Ruby

# frozen_string_literal: true
class ChatSeeder
def execute(args = {})
return if !SiteSetting.needs_chat_seeded
begin
create_category_channel_from(SiteSetting.staff_category_id)
create_category_channel_from(SiteSetting.general_category_id)
rescue => error
Rails.logger.warn("Error seeding chat category - #{error.inspect}")
ensure
SiteSetting.needs_chat_seeded = false
end
end
def create_category_channel_from(category_id)
category = Category.find_by(id: category_id)
return if category.nil?
chat_channel = category.create_chat_channel!(auto_join_users: true, name: category.name)
category.custom_fields[Chat::HAS_CHAT_ENABLED] = true
category.save!
Chat::ChatChannelMembershipManager.new(chat_channel).enforce_automatic_channel_memberships
chat_channel
end
end