From 30fd6c28eec100ba8205f468d4fcf5f4f7e2cfea Mon Sep 17 00:00:00 2001 From: f Date: Tue, 5 Mar 2024 15:46:33 -0300 Subject: [PATCH] feat: enviar un reporte por actore --- app/controllers/activity_pubs_controller.rb | 14 ++++++++++++++ app/controllers/concerns/moderation_concern.rb | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/activity_pubs_controller.rb b/app/controllers/activity_pubs_controller.rb index 37702d96..2b54cacd 100644 --- a/app/controllers/activity_pubs_controller.rb +++ b/app/controllers/activity_pubs_controller.rb @@ -28,6 +28,20 @@ class ActivityPubsController < ApplicationController return unless ActivityPub.events.include? action + # Crear una sola remote flag por autore + if action == :report + message = remote_flag_params(activity_pubs.first).dig(:remote_flag_attributes, :message) + + activity_pubs.distinct.pluck(:actor_id).each do |actor_id| + remote_flag = ActivityPub::RemoteFlag.find_or_initialize_by(actor_id: actor_id, site_id: site.id) + remote_flag.message = message + remote_flag.save + # XXX: Idealmente todas las ActivityPub que enviamos pueden + # cambiar de estado, pero chequeamos de todas formas. + remote_flag.activity_pubs << (activity_pubs.where(actor_id: actor_id).to_a.select { |a| a.public_send(may) }) + end + end + ActivityPub.transaction do activity_pubs.find_each do |activity_pub| next unless activity_pub.public_send(may) diff --git a/app/controllers/concerns/moderation_concern.rb b/app/controllers/concerns/moderation_concern.rb index 5b4c276d..3b9d818f 100644 --- a/app/controllers/concerns/moderation_concern.rb +++ b/app/controllers/concerns/moderation_concern.rb @@ -16,7 +16,7 @@ module ModerationConcern end def remote_flag_params(model) - { remote_flag_attributes: { id: model.remote_flag_id, message: '' } }.tap do |p| + { remote_flag_attributes: { id: model.remote_flag_id, message: ''.dup } }.tap do |p| p[:remote_flag_attributes][:site_id] = model.site_id p[:remote_flag_attributes][:actor_id] = model.actor_id