From 380d484c00aa2b53d171c0c85bc21160482679d0 Mon Sep 17 00:00:00 2001 From: f Date: Sat, 24 Feb 2024 13:04:52 -0300 Subject: [PATCH] feat: poder encontrar instancias a partir de actividades --- app/controllers/moderation_queue_controller.rb | 6 ++++++ app/models/activity_pub/activity.rb | 1 + app/models/activity_pub/actor.rb | 1 + app/models/activity_pub/instance.rb | 4 ++++ app/models/activity_pub/object.rb | 7 +++++++ app/views/moderation_queue/_instance.haml | 18 +++++++----------- app/views/moderation_queue/_instances.haml | 2 +- .../20240223170317_add_actor_to_activities.rb | 18 ++++++++++++++++++ db/structure.sql | 6 ++++-- 9 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20240223170317_add_actor_to_activities.rb diff --git a/app/controllers/moderation_queue_controller.rb b/app/controllers/moderation_queue_controller.rb index eec0c70f..5f94e1f7 100644 --- a/app/controllers/moderation_queue_controller.rb +++ b/app/controllers/moderation_queue_controller.rb @@ -5,6 +5,12 @@ class ModerationQueueController < ApplicationController # Cola de moderación viendo todo el sitio def index dummy_data + + # @todo cambiar el estado por query + @activity_pubs = site.activity_pubs.where(aasm_state: 'paused') + @activities = ActivityPub::Activity.where(activity_pub_id: @activity_pubs.pluck(:id)) + @actors = ActivityPub::Actor.where(id: @activities.unscoped.distinct.pluck(:actor_id)) + @instances = ActivityPub::Instance.where(id: @actors.distinct.pluck(:instance_id)) end # Perfil remoto de usuarie diff --git a/app/models/activity_pub/activity.rb b/app/models/activity_pub/activity.rb index 5ee3d2d1..a220b831 100644 --- a/app/models/activity_pub/activity.rb +++ b/app/models/activity_pub/activity.rb @@ -16,6 +16,7 @@ class ActivityPub include ActivityPub::Concerns::JsonLdConcern belongs_to :activity_pub + belongs_to :actor has_one :object, through: :activity_pub validates :activity_pub_id, presence: true diff --git a/app/models/activity_pub/actor.rb b/app/models/activity_pub/actor.rb index e79a596a..7a858a7e 100644 --- a/app/models/activity_pub/actor.rb +++ b/app/models/activity_pub/actor.rb @@ -11,5 +11,6 @@ class ActivityPub belongs_to :instance has_many :activity_pubs, as: :object + has_many :activities end end diff --git a/app/models/activity_pub/instance.rb b/app/models/activity_pub/instance.rb index b13b8676..17bf183d 100644 --- a/app/models/activity_pub/instance.rb +++ b/app/models/activity_pub/instance.rb @@ -19,5 +19,9 @@ class ActivityPub state :allowed state :blocked end + + def uri + @uri ||= "https://#{hostname}/" + end end end diff --git a/app/models/activity_pub/object.rb b/app/models/activity_pub/object.rb index 898d5375..c196160f 100644 --- a/app/models/activity_pub/object.rb +++ b/app/models/activity_pub/object.rb @@ -6,5 +6,12 @@ class ActivityPub include ActivityPub::Concerns::JsonLdConcern has_many :activity_pubs, as: :object + + # Encontrar le Actor por su relación con el objeto + # + # @return [ActivityPub::Actor,nil] + def actor + ActivityPub::Actor.find_by(uri: content['actor']) + end end end diff --git a/app/views/moderation_queue/_instance.haml b/app/views/moderation_queue/_instance.haml index cff8a957..958a0199 100644 --- a/app/views/moderation_queue/_instance.haml +++ b/app/views/moderation_queue/_instance.haml @@ -1,16 +1,12 @@ -- host = instance['domain'] -- host ||= instance['uri'] -- hosthttps = "https://#{host}" - .row.no-gutters.pt-2 .col-1 - = render 'components/checkbox', id: host + = render 'components/checkbox', id: instance.hostname .col-11 - %h4 - %a{ href: hosthttps }= instance['title'] - %p= instance['description'].html_safe - %p + %h4 + %a{ href: instance.uri }= instance.content['title'] + %p= instance.content['description'].html_safe + %p %span= t('.users') %span - = instance.dig('usage', 'users', 'active_month') - = instance.dig('stats', 'user_count') + = instance.content.dig('usage', 'users', 'active_month') + = instance.content.dig('stats', 'user_count') diff --git a/app/views/moderation_queue/_instances.haml b/app/views/moderation_queue/_instances.haml index 1accf60d..e836d7e0 100644 --- a/app/views/moderation_queue/_instances.haml +++ b/app/views/moderation_queue/_instances.haml @@ -7,7 +7,7 @@ -# Botones moderación .d-flex.pb-4 - = render 'components/instances_btn_box' + = render 'components/instances_btn_box', instance: instance %hr %h3.mt-5= t('moderation_queue.instances.title') diff --git a/db/migrate/20240223170317_add_actor_to_activities.rb b/db/migrate/20240223170317_add_actor_to_activities.rb new file mode 100644 index 00000000..a546cd94 --- /dev/null +++ b/db/migrate/20240223170317_add_actor_to_activities.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +# Relaciona Actor con Activity +class AddActorToActivities < ActiveRecord::Migration[6.1] + def up + add_column :activity_pub_activities, :actor_id, :uuid, index: true + + ActivityPub::Activity.find_each do |activity| + actor = ActivityPub::Actor.find_by(uri: activity.content['actor']) + + activity.update(actor: actor) if actor.present? + end + end + + def down + remove_column :activity_pub_activities, :actor_id, :uuid, index: true + end +end diff --git a/db/structure.sql b/db/structure.sql index ee99e791..97e9ba36 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -484,7 +484,8 @@ CREATE TABLE public.activity_pub_activities ( activity_pub_id uuid NOT NULL, type character varying NOT NULL, uri character varying NOT NULL, - content jsonb DEFAULT '{}'::jsonb + content jsonb DEFAULT '{}'::jsonb, + actor_id uuid ); @@ -2472,6 +2473,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20240219204011'), ('20240219204224'), ('20240220161414'), -('20240221184007'); +('20240221184007'), +('20240223170317');