From b255acf2fd98d2541a8bf6277390a7dc06609843 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 4 Mar 2024 11:59:29 -0300 Subject: [PATCH] feat: comentarios por actore --- .../v1/webhooks/social_inbox_controller.rb | 2 +- .../moderation_queue_controller.rb | 1 + app/models/activity_pub.rb | 1 + app/processors/activity_pub_processor.rb | 15 ++++++++ app/views/moderation_queue/_comment.haml | 37 +++++++++---------- app/views/moderation_queue/_comments.haml | 10 ++--- app/views/moderation_queue/index.haml | 4 +- ...301202955_add_actor_id_to_activity_pubs.rb | 16 ++++++++ db/structure.sql | 6 ++- 9 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 app/processors/activity_pub_processor.rb create mode 100644 db/migrate/20240301202955_add_actor_id_to_activity_pubs.rb diff --git a/app/controllers/api/v1/webhooks/social_inbox_controller.rb b/app/controllers/api/v1/webhooks/social_inbox_controller.rb index fda51f49..464a0ffe 100644 --- a/app/controllers/api/v1/webhooks/social_inbox_controller.rb +++ b/app/controllers/api/v1/webhooks/social_inbox_controller.rb @@ -134,7 +134,7 @@ module Api # # @return [ActivityPub] def activity_pub - @activity_pub ||= site.activity_pubs.find_or_create_by!(site: site, instance: instance, object_id: object.id, object_type: object.type) + @activity_pub ||= site.activity_pubs.find_or_create_by!(site: site, actor: actor, instance: instance, object_id: object.id, object_type: object.type) end # Crea la actividad y la vincula con el estado diff --git a/app/controllers/moderation_queue_controller.rb b/app/controllers/moderation_queue_controller.rb index 95639b35..b803ccc9 100644 --- a/app/controllers/moderation_queue_controller.rb +++ b/app/controllers/moderation_queue_controller.rb @@ -12,6 +12,7 @@ class ModerationQueueController < ApplicationController @activity_pubs = site.activity_pubs @instance_moderations = rubanok_process(site.instance_moderations, with: InstanceModerationProcessor) @actor_moderations = rubanok_process(site.actor_moderations, with: ActorModerationProcessor) + @moderation_queue = rubanok_process(site.activity_pubs, with: ActivityPubProcessor) end # todon.nl está usando /api/v2/instance diff --git a/app/models/activity_pub.rb b/app/models/activity_pub.rb index 86c3f240..b52c2a76 100644 --- a/app/models/activity_pub.rb +++ b/app/models/activity_pub.rb @@ -13,6 +13,7 @@ class ActivityPub < ApplicationRecord belongs_to :instance belongs_to :site belongs_to :object, polymorphic: true + belongs_to :actor has_many :activities validates :site_id, presence: true diff --git a/app/processors/activity_pub_processor.rb b/app/processors/activity_pub_processor.rb new file mode 100644 index 00000000..52cdb6d3 --- /dev/null +++ b/app/processors/activity_pub_processor.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# Gestiona los filtros de ActivityPub +class ActivityPubProcessor < Rubanok::Processor + # En orden descendiente para encontrar la última actividad + # + # Por ahora solo queremos moderar comentarios. + prepare do + raw.where(object_type: %w[ActivityPub::Object::Note ActivityPub::Object::Article]).order(updated_at: :desc) + end + + map :activity_pub_state, activate_always: true do |activity_pub_state: 'paused'| + raw.where(aasm_state: activity_pub_state) + end +end diff --git a/app/views/moderation_queue/_comment.haml b/app/views/moderation_queue/_comment.haml index afd2a335..495aaf55 100644 --- a/app/views/moderation_queue/_comment.haml +++ b/app/views/moderation_queue/_comment.haml @@ -4,24 +4,21 @@ .col-1 = render 'components/checkbox', id: comment['id'] .col-11 - .row.no-gutters - .col.col-lg-10.d-inline-flex.justify-content-between - %h4 - %a{ href: comment['attributedTo'] }= profile['preferredUsername'] + .d-flex.flex-row.align-items-center.justify-content-between + %h4.mb-0 + %a{ href: comment['attributedTo'] }= sanitize profile['preferredUsername'] + %small = render 'layouts/time', time: comment['published'] - - if comment['inReplyTo'] - .row.no-gutters - .col.p-0 - %p - %span= t('.reply_to') - %span - %a{ href: comment['inReplyTo'] }= comment['inReplyTo'] - .row.no-gutters - .col.p-0 - - if comment['summary'] - - summary = comment['summary'] - = render 'layouts/details', summary: summary do - %p= comment['content'].html_safe - - else - %p= comment['content'].html_safe - + - if comment['inReplyTo'].present? + %dl + %dt.d-inline + %small= t('.reply_to') + %dd.d-inline + %small + %a{ href: comment['inReplyTo'] }= sanitize comment['inReplyTo'] + %div + - if comment['summary'].present? + = render 'layouts/details', summary: comment['summary'], summary_class: 'h5' do + = sanitize comment['content'] + - else + = sanitize comment['content'] diff --git a/app/views/moderation_queue/_comments.haml b/app/views/moderation_queue/_comments.haml index eadfd78b..4fe84652 100644 --- a/app/views/moderation_queue/_comments.haml +++ b/app/views/moderation_queue/_comments.haml @@ -1,14 +1,14 @@ .row.no-gutters.pt-2 .col-1.d-flex.align-items-center - = render 'components/checkbox', id: moderation_queue.first['id'] + = render 'components/select_all', id: 'select-all-comments' .col-md-9 -# Filtros = render 'components/comments_filters' -- moderation_queue.each do |comment| +- moderation_queue.each do |activity_pub| %hr - = render 'comment', comment: comment, profile: comment['attributedTo'] - + = render 'comment', comment: activity_pub.object.content, profile: activity_pub.actor.content + -# Botones moderación .d-flex.justify-content-center - = render 'components/comments_btn_box', comment: comment \ No newline at end of file + = render 'components/comments_btn_box', comment: activity_pub.object.content diff --git a/app/views/moderation_queue/index.haml b/app/views/moderation_queue/index.haml index 799fc641..80f0bd7c 100644 --- a/app/views/moderation_queue/index.haml +++ b/app/views/moderation_queue/index.haml @@ -7,7 +7,7 @@ = render 'moderation_queue/instances', site: @site, instance_moderations: @instance_moderations, fediblock_states: @site.fediblock_states %hr = render 'layouts/details', id: 'accounts', summary: t('.accounts') do - = render 'moderation_queue/accounts', site: @site, post: @post, actor_moderations: @actor_moderations + = render 'moderation_queue/accounts', site: @site, actor_moderations: @actor_moderations %hr = render 'layouts/details', id: 'comments', summary: t('.comments') do - = render 'moderation_queue/comments', site: @site, post: @post, moderation_queue: @moderation_queue + = render 'moderation_queue/comments', site: @site, moderation_queue: @moderation_queue diff --git a/db/migrate/20240301202955_add_actor_id_to_activity_pubs.rb b/db/migrate/20240301202955_add_actor_id_to_activity_pubs.rb new file mode 100644 index 00000000..37db4bfc --- /dev/null +++ b/db/migrate/20240301202955_add_actor_id_to_activity_pubs.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +# Relaciona estados de actividades con les actores que las hicieron +class AddActorIdToActivityPubs < ActiveRecord::Migration[6.1] + def up + add_column :activity_pubs, :actor_id, :uuid + + ActivityPub.all.find_each do |activity_pub| + activity_pub.update_column(:actor_id, activity_pub.activities.last.actor_id) + end + end + + def down + remove_column :activity_pubs, :actor_id + end +end diff --git a/db/structure.sql b/db/structure.sql index 38a56b46..ca3a868b 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -572,7 +572,8 @@ CREATE TABLE public.activity_pubs ( object_id uuid NOT NULL, object_type character varying NOT NULL, aasm_state character varying NOT NULL, - instance_id uuid + instance_id uuid, + actor_id uuid ); @@ -2699,6 +2700,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20240228171335'), ('20240228202830'), ('20240229201155'), -('20240301181224'); +('20240301181224'), +('20240301202955');