2024-02-27 19:39:02 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub
|
|
|
|
# Bloquea varias instancias de una sola vez
|
|
|
|
class InstanceModerationJob < ApplicationJob
|
|
|
|
# @param :site [Site]
|
|
|
|
# @param :hostnames [Array<String>]
|
2024-03-13 18:29:34 +00:00
|
|
|
# @param :perform_remotely [Bool]
|
|
|
|
def perform(site:, hostnames:, perform_remotely: true)
|
2024-02-27 19:39:02 +00:00
|
|
|
# Crear las instancias que no existan todavía
|
|
|
|
hostnames.each do |hostname|
|
2024-03-22 20:31:53 +00:00
|
|
|
ActivityPub::Instance.lock.find_or_create_by(hostname: hostname)
|
2024-02-27 19:39:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
instances = ActivityPub::Instance.where(hostname: hostnames)
|
|
|
|
|
|
|
|
Site.transaction do
|
|
|
|
# Crea todas las moderaciones de instancia con un estado por
|
|
|
|
# defecto si no existen
|
|
|
|
instances.find_each do |instance|
|
|
|
|
# Esto bloquea cada una individualmente en la Social Inbox,
|
|
|
|
# idealmente son pocas instancias las que aparecen.
|
2024-03-22 20:31:53 +00:00
|
|
|
site.instance_moderations.lock.find_or_create_by(instance: instance)
|
2024-02-27 19:39:02 +00:00
|
|
|
end
|
2024-03-08 17:42:27 +00:00
|
|
|
|
2024-03-13 18:29:34 +00:00
|
|
|
scope = site.instance_moderations.where(instance_id: instances.ids)
|
|
|
|
|
|
|
|
if perform_remotely
|
|
|
|
scope.block_all!
|
|
|
|
else
|
|
|
|
scope.block_all_without_callbacks!
|
|
|
|
end
|
2024-03-16 22:05:12 +00:00
|
|
|
|
|
|
|
ActivityPub::SyncListsJob.perform_later(site: site)
|
2024-03-12 16:57:31 +00:00
|
|
|
end
|
2024-02-27 19:39:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|