discourse/plugins/chat/lib/discourse_dev/message.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

31 lines
808 B
Ruby

# frozen_string_literal: true
require "discourse_dev/record"
require "faker"
module DiscourseDev
class Message < Record
def initialize
super(::ChatMessage, 200)
end
def data
if Faker::Boolean.boolean(true_ratio: 0.5)
channel = ::ChatChannel.where(chatable_type: "DirectMessage").order("RANDOM()").first
channel.user_chat_channel_memberships.update_all(following: true)
user = channel.chatable.users.order("RANDOM()").first
else
membership = ::UserChatChannelMembership.order("RANDOM()").first
channel = membership.chat_channel
user = membership.user
end
{ user: user, content: Faker::Lorem.paragraph, chat_channel: channel }
end
def create!
Chat::ChatMessageCreator.create(data)
end
end
end