From 2d424676fc330d31dde82b5e34b21411b3b7b8fb Mon Sep 17 00:00:00 2001 From: Osama Sayegh Date: Tue, 7 Jan 2025 03:05:34 +0300 Subject: [PATCH] DEV: Extend the reviewables:populate rake task in chat (#30597) Related to https://github.com/discourse/discourse/commit/5a55c9062a81458f013ff6d0d52359bbd9ba2dab The chat plugin now makes use of the plugin API that was added in the linked commit for extending the reviewables:populate rake task. --- plugins/chat/lib/discourse_dev/message.rb | 14 +++++++++++-- .../lib/discourse_dev/reviewable_message.rb | 21 +++++++++++++++++++ plugins/chat/plugin.rb | 2 ++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 plugins/chat/lib/discourse_dev/reviewable_message.rb diff --git a/plugins/chat/lib/discourse_dev/message.rb b/plugins/chat/lib/discourse_dev/message.rb index 531495dc41b..4d0686ff5f2 100644 --- a/plugins/chat/lib/discourse_dev/message.rb +++ b/plugins/chat/lib/discourse_dev/message.rb @@ -24,11 +24,21 @@ module DiscourseDev ::Chat::UserChatChannelMembership.where(chat_channel: channel).order("RANDOM()").first user = membership.user - { guardian: user.guardian, message: Faker::Lorem.paragraph, chat_channel_id: channel.id } + { + guardian: user.guardian, + params: { + message: Faker::Lorem.paragraph, + chat_channel_id: channel.id, + }, + } end def create! - Chat::CreateMessage.call(data) + message = nil + Chat::CreateMessage.call(data) do + on_success { |message_instance:| message = message_instance } + end + message end end end diff --git a/plugins/chat/lib/discourse_dev/reviewable_message.rb b/plugins/chat/lib/discourse_dev/reviewable_message.rb new file mode 100644 index 00000000000..97a75e201f0 --- /dev/null +++ b/plugins/chat/lib/discourse_dev/reviewable_message.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module DiscourseDev + class ReviewableMessage < Reviewable + def populate! + channel = CategoryChannel.new.create! + message = Message.new(channel_id: channel.id, count: 1).create! + user = @users.sample + + ::Chat::FlagMessage.call( + guardian: user.guardian, + params: { + channel_id: channel.id, + message_id: message.id, + flag_type_id: + ReviewableScore.types.slice(:off_topic, :inappropriate, :spam, :illegal).values.sample, + }, + ) + end + end +end diff --git a/plugins/chat/plugin.rb b/plugins/chat/plugin.rb index 915d7f3e11e..cebcbaac8f7 100644 --- a/plugins/chat/plugin.rb +++ b/plugins/chat/plugin.rb @@ -512,6 +512,8 @@ after_initialize do # When we eventually allow secure_uploads in chat, this will need to be # removed. Depending on the channel, uploads may end up being secure. UploadSecurity.register_custom_public_type("chat-composer") + + DiscoursePluginRegistry.discourse_dev_populate_reviewable_types.add DiscourseDev::ReviewableMessage end if Rails.env == "test"