From 9e54d6311c0fbd9a7dfc34ab5b37460cf97b1021 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 24 Feb 2024 12:46:55 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20obtener=20informaci=C3=B3n=20de=20le=20?= =?UTF-8?q?actore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1/webhooks/social_inbox_controller.rb | 2 ++ app/jobs/activity_pub/actor_fetch_job.rb | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 app/jobs/activity_pub/actor_fetch_job.rb diff --git a/app/controllers/api/v1/webhooks/social_inbox_controller.rb b/app/controllers/api/v1/webhooks/social_inbox_controller.rb index 97ca58b5..a5951716 100644 --- a/app/controllers/api/v1/webhooks/social_inbox_controller.rb +++ b/app/controllers/api/v1/webhooks/social_inbox_controller.rb @@ -154,6 +154,8 @@ module Api ActivityPub::InstanceFetchJob.perform_later(site: site, instance: a.instance) a.save! + + ActivityPub::ActorFetchJob.perform_later(site: site, actor: a) end end diff --git a/app/jobs/activity_pub/actor_fetch_job.rb b/app/jobs/activity_pub/actor_fetch_job.rb new file mode 100644 index 00000000..1c6f1735 --- /dev/null +++ b/app/jobs/activity_pub/actor_fetch_job.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +# Obtiene o actualiza el contenido de un objeto, usando las credenciales +# del sitio. +# +# XXX: Esto usa las credenciales del sitio para volver el objeto +# disponible para todo el CMS. Asumimos que el objeto devuelto es el +# mismo para todo el mundo y las credenciales solo son para +# autenticación. +class ActivityPub + class ActorFetchJob < ApplicationJob + def perform(site:, actor:) + ActivityPub::Actor.transaction do + response = site.social_inbox.dereferencer.get(uri: actor.uri) + + # @todo Fallar cuando la respuesta no funcione? + return unless response.ok? + return if response.miss? && actor.content.present? + + actor.update(content: FastJsonparser.parse(response.body)) + end + end + end +end