2024-02-27 19:39:02 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ActivityPub
|
|
|
|
# Bloquea varias instancias de una sola vez
|
|
|
|
class InstanceModerationJob < ApplicationJob
|
2024-02-27 19:53:48 +00:00
|
|
|
self.priority = 50
|
|
|
|
|
2024-02-27 19:39:02 +00:00
|
|
|
# @param :site [Site]
|
|
|
|
# @param :hostnames [Array<String>]
|
|
|
|
def perform(site:, hostnames:)
|
|
|
|
# Crear las instancias que no existan todavía
|
|
|
|
hostnames.each do |hostname|
|
|
|
|
ActivityPub::Instance.find_or_create_by(hostname: hostname)
|
|
|
|
end
|
|
|
|
|
|
|
|
instances = ActivityPub::Instance.where(hostname: hostnames)
|
2024-03-08 17:42:27 +00:00
|
|
|
success = true
|
2024-02-27 19:39:02 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
site.instance_moderations.find_or_create_by(instance: instance).tap do |instance_moderation|
|
|
|
|
instance_moderation.block! if instance_moderation.may_block?
|
2024-03-08 17:42:27 +00:00
|
|
|
# Notificar todos los errores sin detener la ejecución
|
|
|
|
rescue Exception => e
|
|
|
|
ExceptionNotifier.notify_exception(e, data: { site: site.name, instance_moderation: instance_moderation.id })
|
|
|
|
success = false
|
2024-02-27 19:39:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-03-08 17:42:27 +00:00
|
|
|
|
|
|
|
success
|
2024-02-27 19:39:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|