5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 06:56:22 +00:00

BREAKING CHANGE: renombrar instancias por hostnames

This commit is contained in:
f 2024-02-28 15:47:40 -03:00
parent 7521f598a6
commit 15800e1096
No known key found for this signature in database
6 changed files with 28 additions and 10 deletions

View file

@ -11,12 +11,12 @@ class ActivityPub
ActivityPub::Fediblock.find_each do |fediblock|
fediblock.process!
instances_added = fediblock.instances - fediblock.instances_was
hostnames_added = fediblock.hostnames - fediblock.hostnames_was
# No hacer nada si no cambió con respecto a la versión anterior
next if instances_added.empty?
next if hostnames_added.empty?
ActivityPub::FediblockUpdatedJob.perform_later(fediblock: fediblock, hostnames: instances_added)
ActivityPub::FediblockUpdatedJob.perform_later(fediblock: fediblock, hostnames: hostnames_added)
rescue ActivityPub::Fediblock::FediblockDownloadError => e
ExceptionNotifier.notify_exception(e, data: { fediblock: fediblock.title })
end

View file

@ -2,14 +2,17 @@
# Se encarga de mantener sincronizadas las listas de instancias
# de los fediblocks con los sitios que las tengan activadas.
#
# También va a asociar las listas con todos los sitios que tengan la
# Social Inbox habilitada.
class ActivityPub
class FediblockUpdatedJob < ApplicationJob
self.priority = 50
# @param :fediblock [ActivityPub::Fediblock]
# @param :instances [Array<String>]
# @param :hostnames [Array<String>]
def perform(fediblock:, hostnames:)
instances = ActivityPub::Instance.where(hostname: instances)
instances = ActivityPub::Instance.where(hostname: hostnames)
# Todos los sitios con la Social Inbox habilitada
Site.where(id: DeploySocialDistributedPress.pluck(:site_id)).find_each do |site|
@ -19,7 +22,7 @@ class ActivityPub
# No hace nada con los deshabilitados
next unless fediblock_state.enabled?
ActivityPub::InstanceModerationJob.perform_later(site: site, hostnames: instances)
ActivityPub::InstanceModerationJob.perform_later(site: site, hostnames: hostnames)
end
end
end

View file

@ -43,6 +43,11 @@ class ActivityPub
@client ||= Client.new
end
# Todas las instancias de este fediblock
def instances
ActivityPub::Instance.where(hostname: hostnames)
end
# Descarga la lista y crea las instancias con el estado necesario
def process!
response = client.get(download_url)
@ -53,7 +58,7 @@ class ActivityPub
csv = response.parsed_response
process_csv! csv
update(instances: csv.map { |r| r[hostname_header] })
update(hostnames: csv.map { |r| r[hostname_header] })
end
end

View file

@ -7,6 +7,6 @@
%dl.mb-0
%dt.d-inline= t('.instances_blocked')
%dd.d-inline.font-weight-normal= blocklist.instances.count
%dd.d-inline.font-weight-normal= blocklist.hostnames.count
%p.mb-0.font-weight-normal
%a{ href: blocklist.url }= know_more

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
# Cambia el nombre de la columna para que podamos obtener todas las
# instancias de un fediblock
class RenameFediblockInstancesToHostnames < ActiveRecord::Migration[6.1]
def change
rename_column :activity_pub_fediblocks, :instances, :hostnames
end
end

View file

@ -514,7 +514,7 @@ CREATE TABLE public.activity_pub_fediblocks (
url character varying NOT NULL,
download_url character varying NOT NULL,
format character varying NOT NULL,
instances jsonb DEFAULT '[]'::jsonb
hostnames jsonb DEFAULT '[]'::jsonb
);
@ -2615,6 +2615,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20240226133022'),
('20240226134335'),
('20240227134845'),
('20240227142019');
('20240227142019'),
('20240228171335');