mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 22:28:14 +08:00
abcaa1a961
This is a followup of the previous refactor where we created two new models to handle all the dedicated logic that was present in the `ChatChannel` model. For the sake of consistency, `DMChannel` has been renamed to `DirectMessageChannel` and the previous `DirectMessageChannel` model is now named `DirectMessage`. This should help reasoning about direct messages.
32 lines
719 B
Ruby
32 lines
719 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "discourse_dev/record"
|
|
require "faker"
|
|
|
|
module DiscourseDev
|
|
class DirectChannel < Record
|
|
def initialize
|
|
super(::DirectMessage, 5)
|
|
end
|
|
|
|
def data
|
|
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
|
|
|
|
[User.new.create!, admin_user || User.new.create!]
|
|
end
|
|
|
|
def create!
|
|
users = data
|
|
Chat::DirectMessageChannelCreator.create!(acting_user: users[0], target_users: users)
|
|
end
|
|
end
|
|
end
|