mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 04:01:18 +08:00
DEV: Migrate Chat::MessageCreator
to a service (#22390)
Currently, the logic for creating a new chat message is scattered between a controller and an “old” service. This patch address this issue by creating a new service (using the “new” sevice object system) encapsulating all the necessary logic. (authorization, publishing events, etc.)
This commit is contained in:
@ -45,8 +45,10 @@ module DiscourseDev
|
||||
Faker::Number
|
||||
.between(from: 20, to: 80)
|
||||
.times do
|
||||
Chat::MessageCreator.create(
|
||||
{ user: users.sample, chat_channel: channel, content: Faker::Lorem.paragraph },
|
||||
Chat::CreateMessage.call(
|
||||
guardian: users.sample.guardian,
|
||||
chat_channel_id: channel.id,
|
||||
message: Faker::Lorem.paragraph,
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -24,11 +24,11 @@ module DiscourseDev
|
||||
::Chat::UserChatChannelMembership.where(chat_channel: channel).order("RANDOM()").first
|
||||
user = membership.user
|
||||
|
||||
{ user: user, content: Faker::Lorem.paragraph, chat_channel: channel }
|
||||
{ guardian: user.guardian, message: Faker::Lorem.paragraph, chat_channel_id: channel.id }
|
||||
end
|
||||
|
||||
def create!
|
||||
Chat::MessageCreator.create(data)
|
||||
Chat::CreateMessage.call(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -26,11 +26,11 @@ module DiscourseDev
|
||||
user = membership.user
|
||||
|
||||
om =
|
||||
Chat::MessageCreator.create(
|
||||
user: user,
|
||||
content: Faker::Lorem.paragraph,
|
||||
chat_channel: channel,
|
||||
).chat_message
|
||||
Chat::CreateMessage.call(
|
||||
guardian: user.guardian,
|
||||
message: Faker::Lorem.paragraph,
|
||||
chat_channel_id: channel.id,
|
||||
).message
|
||||
|
||||
{ original_message_user: user, original_message: om, channel: channel }
|
||||
end
|
||||
@ -45,11 +45,11 @@ module DiscourseDev
|
||||
.first
|
||||
.user
|
||||
@message_count.times do
|
||||
Chat::MessageCreator.create(
|
||||
Chat::CreateMessage.call(
|
||||
{
|
||||
user: user,
|
||||
chat_channel: thread.channel,
|
||||
content: Faker::Lorem.paragraph,
|
||||
guardian: user.guardian,
|
||||
chat_channel_id: thread.channel_id,
|
||||
message: Faker::Lorem.paragraph,
|
||||
thread_id: thread.id,
|
||||
},
|
||||
)
|
||||
|
Reference in New Issue
Block a user