discourse/plugins/chat/lib/discourse_dev/direct_channel.rb
Loïc Guitaut abcaa1a961 DEV: Rename direct message related models
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.
2022-11-03 14:39:23 +01:00

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