mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
DEV: Move discourse-chat
to the core repo. (#18776)
As part of this move, we are also renaming `discourse-chat` to `chat`.
This commit is contained in:
44
plugins/chat/lib/discourse_dev/public_channel.rb
Normal file
44
plugins/chat/lib/discourse_dev/public_channel.rb
Normal file
@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "discourse_dev/record"
|
||||
require "faker"
|
||||
|
||||
module DiscourseDev
|
||||
class PublicChannel < Record
|
||||
def initialize
|
||||
super(::CategoryChannel, 5)
|
||||
end
|
||||
|
||||
def data
|
||||
chatable = Category.random
|
||||
|
||||
{
|
||||
chatable: chatable,
|
||||
description: Faker::Lorem.paragraph,
|
||||
user_count: 1,
|
||||
name: Faker::Company.name,
|
||||
created_at: Faker::Time.between(from: DiscourseDev.config.start_date, to: DateTime.now),
|
||||
}
|
||||
end
|
||||
|
||||
def create!
|
||||
super do |channel|
|
||||
Faker::Number
|
||||
.between(from: 5, to: 10)
|
||||
.times do
|
||||
if Faker::Boolean.boolean(true_ratio: 0.5)
|
||||
admin_username =
|
||||
begin
|
||||
DiscourseDev::Config.new.config[:admin][:username]
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
admin_user = ::User.find_by(username: admin_username) if admin_username
|
||||
end
|
||||
|
||||
Chat::ChatChannelMembershipManager.new(channel).follow(admin_user || User.new.create!)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user