mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 04:46:21 +00:00
30 lines
1,009 B
Ruby
30 lines
1,009 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
class ActivityPub
|
||
|
# Bloquea varias instancias de una sola vez
|
||
|
class InstanceModerationJob < ApplicationJob
|
||
|
# @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)
|
||
|
|
||
|
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?
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|