diff --git a/app/controllers/api/v1/webhooks/social_inbox_controller.rb b/app/controllers/api/v1/webhooks/social_inbox_controller.rb index e51b89dd..3341b33d 100644 --- a/app/controllers/api/v1/webhooks/social_inbox_controller.rb +++ b/app/controllers/api/v1/webhooks/social_inbox_controller.rb @@ -27,7 +27,9 @@ module Api activity.update_activity_pub_state! end rescue ActiveRecord::RecordInvalid => e - ExceptionNotifier.notify_exception(e, data: { site: site.name, usuarie: usuarie.email, activity: original_activity }) + ExceptionNotifier.notify_exception(e, + data: { site: site.name, usuarie: usuarie.email, + activity: original_activity }) ensure head :accepted end @@ -59,11 +61,9 @@ module Api # @return [String] def object_uri @object_uri ||= - begin - case original_activity[:object] - when String then original_activity[:object] - when Hash then original_activity.dig(:object, :id) - end + case original_activity[:object] + when String then original_activity[:object] + when Hash then original_activity.dig(:object, :id) end ensure raise ActiveRecord::RecordNotFound, 'object id missing' unless @object_uri @@ -82,7 +82,8 @@ module Api # # @return [ActivityPub::Object] def object - @object ||= ActivityPub::Object.type_from(original_object).find_or_initialize_by(actor: actor, uri: object_uri).tap do |o| + @object ||= ActivityPub::Object.type_from(original_object).find_or_initialize_by(actor: actor, + uri: object_uri).tap do |o| if object_embedded? o.content = original_object else @@ -104,7 +105,8 @@ module Api # # @return [ActivityPub::Activity] def activity - @activity ||= ActivityPub::Activity.type_from(original_activity).new(uri: original_activity[:id], activity_pub: activity_pub).tap do |a| + @activity ||= ActivityPub::Activity.type_from(original_activity).new(uri: original_activity[:id], + activity_pub: activity_pub).tap do |a| a.content = original_activity.dup a.content[:object] = object.uri a.save! diff --git a/app/jobs/activity_pub/fetch_job.rb b/app/jobs/activity_pub/fetch_job.rb index 097a8d32..ff14c795 100644 --- a/app/jobs/activity_pub/fetch_job.rb +++ b/app/jobs/activity_pub/fetch_job.rb @@ -7,16 +7,18 @@ # 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::FetchJob < ApplicationJob - def perform(site:, object:) - ActivityPub::Object.transaction do - response = site.social_inbox.dereferencer.get(uri: object.uri) +class ActivityPub + class FetchJob < ApplicationJob + def perform(site:, object:) + ActivityPub::Object.transaction do + response = site.social_inbox.dereferencer.get(uri: object.uri) - # @todo Fallar cuando la respuesta no funcione? - return unless response.ok? - return unless response.miss? + # @todo Fallar cuando la respuesta no funcione? + return unless response.ok? + return unless response.miss? - object.update(content: FastJsonparser.parse(response.body)) + object.update(content: FastJsonparser.parse(response.body)) + end end end end diff --git a/app/models/activity_pub/activity.rb b/app/models/activity_pub/activity.rb index a1f734e0..5ee3d2d1 100644 --- a/app/models/activity_pub/activity.rb +++ b/app/models/activity_pub/activity.rb @@ -11,19 +11,21 @@ # envía como referencia en lugar de anidarlo. # # @see {https://www.w3.org/TR/activitypub/#client-to-server-interactions} -class ActivityPub::Activity < ApplicationRecord - include ActivityPub::Concerns::JsonLdConcern +class ActivityPub + class Activity < ApplicationRecord + include ActivityPub::Concerns::JsonLdConcern - belongs_to :activity_pub - has_one :object, through: :activity_pub + belongs_to :activity_pub + has_one :object, through: :activity_pub - validates :activity_pub_id, presence: true + validates :activity_pub_id, presence: true - # Siempre en orden descendiente para saber el último estado - default_scope -> { order(created_at: :desc) } + # Siempre en orden descendiente para saber el último estado + default_scope -> { order(created_at: :desc) } - # Cambia la máquina de estados según el tipo de actividad - def update_activity_pub_state! - nil + # Cambia la máquina de estados según el tipo de actividad + def update_activity_pub_state! + nil + end end end diff --git a/app/models/activity_pub/activity/create.rb b/app/models/activity_pub/activity/create.rb index 3dcba5c2..4acafaf2 100644 --- a/app/models/activity_pub/activity/create.rb +++ b/app/models/activity_pub/activity/create.rb @@ -1,3 +1,7 @@ # frozen_string_literal: true -class ActivityPub::Activity::Create < ActivityPub::Activity; end +class ActivityPub + module Activity + class Create < ActivityPub::Activity; end + end +end diff --git a/app/models/activity_pub/activity/delete.rb b/app/models/activity_pub/activity/delete.rb index 1730d49d..2973f730 100644 --- a/app/models/activity_pub/activity/delete.rb +++ b/app/models/activity_pub/activity/delete.rb @@ -1,9 +1,13 @@ # frozen_string_literal: true -class ActivityPub::Activity::Delete < ActivityPub::Activity - # Si estamos eliminando el objeto, tenemos que vaciar su contenido y - # cambiar el estado a borrado - def update_activity_pub_state! - activity_pub.deleted! +class ActivityPub + module Activity + class Delete < ActivityPub::Activity + # Si estamos eliminando el objeto, tenemos que vaciar su contenido y + # cambiar el estado a borrado + def update_activity_pub_state! + activity_pub.deleted! + end + end end end diff --git a/app/models/activity_pub/activity/flag.rb b/app/models/activity_pub/activity/flag.rb index 2911911e..27bbe266 100644 --- a/app/models/activity_pub/activity/flag.rb +++ b/app/models/activity_pub/activity/flag.rb @@ -1,3 +1,7 @@ # frozen_string_literal: true -class ActivityPub::Activity::Flag < ActivityPub::Activity; end +class ActivityPub + module Activity + class Flag < ActivityPub::Activity; end + end +end diff --git a/app/models/activity_pub/activity/follow.rb b/app/models/activity_pub/activity/follow.rb index c22dfd51..9e32b67d 100644 --- a/app/models/activity_pub/activity/follow.rb +++ b/app/models/activity_pub/activity/follow.rb @@ -4,4 +4,8 @@ # # Una actividad de seguimiento se refiere siempre a une actore (el # sitio) y proviene de otre actore. -class ActivityPub::Activity::Follow < ActivityPub::Activity; end +class ActivityPub + module Activity + class Follow < ActivityPub::Activity; end + end +end diff --git a/app/models/activity_pub/activity/generic.rb b/app/models/activity_pub/activity/generic.rb index 8bf76471..89c26247 100644 --- a/app/models/activity_pub/activity/generic.rb +++ b/app/models/activity_pub/activity/generic.rb @@ -1,3 +1,7 @@ # frozen_string_literal: true -class ActivityPub::Activity::Generic < ActivityPub::Activity; end +class ActivityPub + module Activity + class Generic < ActivityPub::Activity; end + end +end diff --git a/app/models/activity_pub/activity/undo.rb b/app/models/activity_pub/activity/undo.rb index a4915394..98233af9 100644 --- a/app/models/activity_pub/activity/undo.rb +++ b/app/models/activity_pub/activity/undo.rb @@ -4,5 +4,9 @@ # # Deshace una actividad, dependiendo de la actividad a la que se # refiere. -class ActivityPub::Activity::Undo < ActivityPub::Activity +class ActivityPub + module Activity + class Undo < ActivityPub::Activity + end + end end diff --git a/app/models/activity_pub/activity/update.rb b/app/models/activity_pub/activity/update.rb index e9203ba5..50622b93 100644 --- a/app/models/activity_pub/activity/update.rb +++ b/app/models/activity_pub/activity/update.rb @@ -1,9 +1,13 @@ # frozen_string_literal: true -class ActivityPub::Activity::Update < ActivityPub::Activity - # Si estamos actualizando el objeto, tenemos que devolverlo a estado - # de moderación - def update_activity_pub_state! - activity_pub.pause! if activity_pub.approved? +class ActivityPub + module Activity + class Update < ActivityPub::Activity + # Si estamos actualizando el objeto, tenemos que devolverlo a estado + # de moderación + def update_activity_pub_state! + activity_pub.pause! if activity_pub.approved? + end + end end end diff --git a/app/models/activity_pub/actor.rb b/app/models/activity_pub/actor.rb index f29c382a..7be69602 100644 --- a/app/models/activity_pub/actor.rb +++ b/app/models/activity_pub/actor.rb @@ -5,10 +5,12 @@ # Actor es la entidad que realiza acciones en ActivityPub # # @todo Obtener el perfil dinámicamente -class ActivityPub::Actor < ApplicationRecord - include ActivityPub::Concerns::JsonLdConcern +class ActivityPub + class Actor < ApplicationRecord + include ActivityPub::Concerns::JsonLdConcern - belongs_to :instance - has_many :activity_pubs, as: :object - has_many :objects + belongs_to :instance + has_many :activity_pubs, as: :object + has_many :objects + end end diff --git a/app/models/activity_pub/instance.rb b/app/models/activity_pub/instance.rb index fe4a777b..b13b8676 100644 --- a/app/models/activity_pub/instance.rb +++ b/app/models/activity_pub/instance.rb @@ -4,18 +4,20 @@ # # Representa cada instancia del fediverso que interactúa con la Social # Inbox. -class ActivityPub::Instance < ApplicationRecord - include AASM +class ActivityPub + class Instance < ApplicationRecord + include AASM - validates :aasm_state, presence: true, inclusion: { in: %w[paused allowed blocked] } - validates :hostname, uniqueness: true, hostname: true + validates :aasm_state, presence: true, inclusion: { in: %w[paused allowed blocked] } + validates :hostname, uniqueness: true, hostname: true - has_many :activity_pubs - has_many :actors + has_many :activity_pubs + has_many :actors - aasm do - state :paused, initial: true - state :allowed - state :blocked + aasm do + state :paused, initial: true + state :allowed + state :blocked + end end end diff --git a/app/models/activity_pub/object.rb b/app/models/activity_pub/object.rb index 519749ef..49a06772 100644 --- a/app/models/activity_pub/object.rb +++ b/app/models/activity_pub/object.rb @@ -1,11 +1,13 @@ # frozen_string_literal: true # Almacena objetos de ActivityPub, como Note, Article, etc. -class ActivityPub::Object < ApplicationRecord - include ActivityPub::Concerns::JsonLdConcern +class ActivityPub + class Object < ApplicationRecord + include ActivityPub::Concerns::JsonLdConcern - belongs_to :actor - has_many :activity_pubs, as: :object + belongs_to :actor + has_many :activity_pubs, as: :object - validates :actor_id, presence: true + validates :actor_id, presence: true + end end diff --git a/app/models/activity_pub/object/application.rb b/app/models/activity_pub/object/application.rb index e8a6f97c..e8d8fa0e 100644 --- a/app/models/activity_pub/object/application.rb +++ b/app/models/activity_pub/object/application.rb @@ -3,4 +3,8 @@ # = Application = # # Una aplicación o instancia -class ActivityPub::Object::Application < ActivityPub::Object; end +class ActivityPub + module Object + class Application < ActivityPub::Object; end + end +end diff --git a/app/models/activity_pub/object/article.rb b/app/models/activity_pub/object/article.rb index ad1a6131..69fe371c 100644 --- a/app/models/activity_pub/object/article.rb +++ b/app/models/activity_pub/object/article.rb @@ -3,4 +3,8 @@ # = Article = # # Representa artículos -class ActivityPub::Object::Article < ActivityPub::Object; end +class ActivityPub + module Object + class Article < ActivityPub::Object; end + end +end diff --git a/app/models/activity_pub/object/generic.rb b/app/models/activity_pub/object/generic.rb index f345e7a9..c16b25c6 100644 --- a/app/models/activity_pub/object/generic.rb +++ b/app/models/activity_pub/object/generic.rb @@ -1,4 +1,8 @@ # frozen_string_literal: true # = Generic = -class ActivityPub::Object::Generic < ActivityPub::Object; end +class ActivityPub + module Object + class Generic < ActivityPub::Object; end + end +end diff --git a/app/models/activity_pub/object/note.rb b/app/models/activity_pub/object/note.rb index 0f84c747..06b969ab 100644 --- a/app/models/activity_pub/object/note.rb +++ b/app/models/activity_pub/object/note.rb @@ -3,4 +3,8 @@ # = Note = # # Representa notas, el tipo más común de objeto del Fediverso. -class ActivityPub::Object::Note < ActivityPub::Object; end +class ActivityPub + module Object + class Note < ActivityPub::Object; end + end +end diff --git a/app/models/activity_pub/object/organization.rb b/app/models/activity_pub/object/organization.rb index a5327d10..31e5887d 100644 --- a/app/models/activity_pub/object/organization.rb +++ b/app/models/activity_pub/object/organization.rb @@ -3,4 +3,8 @@ # = Organization = # # Una organización -class ActivityPub::Object::Organization < ActivityPub::Object; end +class ActivityPub + module Object + class Organization < ActivityPub::Object; end + end +end diff --git a/app/models/activity_pub/object/person.rb b/app/models/activity_pub/object/person.rb index 98a1568d..fd01e515 100644 --- a/app/models/activity_pub/object/person.rb +++ b/app/models/activity_pub/object/person.rb @@ -3,4 +3,8 @@ # = Person = # # Una persona, el perfil de une actore -class ActivityPub::Object::Person < ActivityPub::Object; end +class ActivityPub + module Object + class Person < ActivityPub::Object; end + end +end diff --git a/app/models/social_inbox.rb b/app/models/social_inbox.rb index 624ee571..45b8afd8 100644 --- a/app/models/social_inbox.rb +++ b/app/models/social_inbox.rb @@ -69,8 +69,6 @@ class SocialInbox # # @return [String] def generate_uri(&block) - @public_key_url ||= URI("https://#{hostname}").tap do |uri| - yield uri - end.to_s + @public_key_url ||= URI("https://#{hostname}").tap(&block).to_s end end