mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 11:43:40 +08:00
0a5f548635
As part of this move, we are also renaming `discourse-chat` to `chat`.
45 lines
1.1 KiB
Ruby
45 lines
1.1 KiB
Ruby
# 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
|