mirror of
https://github.com/discourse/discourse.git
synced 2024-12-03 02:23:39 +08:00
6442bbf46c
This is to help generate random channels and chat
messages for local dev. This was removed in 12a18d4d55
presumably because it was not worth refactoring at the
time.
I've only added these tasks:
- `rake chat:message:populate\[113,20\]` (channel_id, count)
- Generates the count of messages for a channel ID provided,
otherwise uses a random channel and 200 count.
- `rake chat:category_channel:populate`
- Creates a chat channel for a random category.
- `rake chat🧵populate\[132,5\]` (channel_id, message_count)
- Creates a thread with N messages in the specified channel,
and enables threading in that channel if necessary
35 lines
870 B
Ruby
35 lines
870 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "discourse_dev/record"
|
|
require "faker"
|
|
|
|
module DiscourseDev
|
|
class Message < Record
|
|
def initialize(channel_id: nil, count: nil, ignore_current_count: false)
|
|
@channel_id = channel_id
|
|
@ignore_current_count = ignore_current_count
|
|
super(::Chat::Message, count&.to_i || 200)
|
|
end
|
|
|
|
def data
|
|
if @channel_id
|
|
channel = ::Chat::Channel.find(@channel_id)
|
|
else
|
|
channel = ::Chat::Channel.where(chatable_type: "Category").order("RANDOM()").first
|
|
end
|
|
|
|
return if !channel
|
|
|
|
membership =
|
|
::Chat::UserChatChannelMembership.where(chat_channel: channel).order("RANDOM()").first
|
|
user = membership.user
|
|
|
|
{ user: user, content: Faker::Lorem.paragraph, chat_channel: channel }
|
|
end
|
|
|
|
def create!
|
|
Chat::MessageCreator.create(data)
|
|
end
|
|
end
|
|
end
|