mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-19 04:26:22 +00:00
chore: rubocop
This commit is contained in:
parent
fb4401fd53
commit
091d5ac41d
20 changed files with 132 additions and 70 deletions
|
@ -27,7 +27,9 @@ module Api
|
||||||
activity.update_activity_pub_state!
|
activity.update_activity_pub_state!
|
||||||
end
|
end
|
||||||
rescue ActiveRecord::RecordInvalid => e
|
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
|
ensure
|
||||||
head :accepted
|
head :accepted
|
||||||
end
|
end
|
||||||
|
@ -59,12 +61,10 @@ module Api
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def object_uri
|
def object_uri
|
||||||
@object_uri ||=
|
@object_uri ||=
|
||||||
begin
|
|
||||||
case original_activity[:object]
|
case original_activity[:object]
|
||||||
when String then original_activity[:object]
|
when String then original_activity[:object]
|
||||||
when Hash then original_activity.dig(:object, :id)
|
when Hash then original_activity.dig(:object, :id)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
ensure
|
ensure
|
||||||
raise ActiveRecord::RecordNotFound, 'object id missing' unless @object_uri
|
raise ActiveRecord::RecordNotFound, 'object id missing' unless @object_uri
|
||||||
end
|
end
|
||||||
|
@ -82,7 +82,8 @@ module Api
|
||||||
#
|
#
|
||||||
# @return [ActivityPub::Object]
|
# @return [ActivityPub::Object]
|
||||||
def 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?
|
if object_embedded?
|
||||||
o.content = original_object
|
o.content = original_object
|
||||||
else
|
else
|
||||||
|
@ -104,7 +105,8 @@ module Api
|
||||||
#
|
#
|
||||||
# @return [ActivityPub::Activity]
|
# @return [ActivityPub::Activity]
|
||||||
def 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 = original_activity.dup
|
||||||
a.content[:object] = object.uri
|
a.content[:object] = object.uri
|
||||||
a.save!
|
a.save!
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
# disponible para todo el CMS. Asumimos que el objeto devuelto es el
|
# disponible para todo el CMS. Asumimos que el objeto devuelto es el
|
||||||
# mismo para todo el mundo y las credenciales solo son para
|
# mismo para todo el mundo y las credenciales solo son para
|
||||||
# autenticación.
|
# autenticación.
|
||||||
class ActivityPub::FetchJob < ApplicationJob
|
class ActivityPub
|
||||||
|
class FetchJob < ApplicationJob
|
||||||
def perform(site:, object:)
|
def perform(site:, object:)
|
||||||
ActivityPub::Object.transaction do
|
ActivityPub::Object.transaction do
|
||||||
response = site.social_inbox.dereferencer.get(uri: object.uri)
|
response = site.social_inbox.dereferencer.get(uri: object.uri)
|
||||||
|
@ -20,3 +21,4 @@ class ActivityPub::FetchJob < ApplicationJob
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
# envía como referencia en lugar de anidarlo.
|
# envía como referencia en lugar de anidarlo.
|
||||||
#
|
#
|
||||||
# @see {https://www.w3.org/TR/activitypub/#client-to-server-interactions}
|
# @see {https://www.w3.org/TR/activitypub/#client-to-server-interactions}
|
||||||
class ActivityPub::Activity < ApplicationRecord
|
class ActivityPub
|
||||||
|
class Activity < ApplicationRecord
|
||||||
include ActivityPub::Concerns::JsonLdConcern
|
include ActivityPub::Concerns::JsonLdConcern
|
||||||
|
|
||||||
belongs_to :activity_pub
|
belongs_to :activity_pub
|
||||||
|
@ -27,3 +28,4 @@ class ActivityPub::Activity < ApplicationRecord
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Create < ActivityPub::Activity; end
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Create < ActivityPub::Activity; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Delete < ActivityPub::Activity
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Delete < ActivityPub::Activity
|
||||||
# Si estamos eliminando el objeto, tenemos que vaciar su contenido y
|
# Si estamos eliminando el objeto, tenemos que vaciar su contenido y
|
||||||
# cambiar el estado a borrado
|
# cambiar el estado a borrado
|
||||||
def update_activity_pub_state!
|
def update_activity_pub_state!
|
||||||
activity_pub.deleted!
|
activity_pub.deleted!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Flag < ActivityPub::Activity; end
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Flag < ActivityPub::Activity; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -4,4 +4,8 @@
|
||||||
#
|
#
|
||||||
# Una actividad de seguimiento se refiere siempre a une actore (el
|
# Una actividad de seguimiento se refiere siempre a une actore (el
|
||||||
# sitio) y proviene de otre actore.
|
# sitio) y proviene de otre actore.
|
||||||
class ActivityPub::Activity::Follow < ActivityPub::Activity; end
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Follow < ActivityPub::Activity; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Generic < ActivityPub::Activity; end
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Generic < ActivityPub::Activity; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -4,5 +4,9 @@
|
||||||
#
|
#
|
||||||
# Deshace una actividad, dependiendo de la actividad a la que se
|
# Deshace una actividad, dependiendo de la actividad a la que se
|
||||||
# refiere.
|
# refiere.
|
||||||
class ActivityPub::Activity::Undo < ActivityPub::Activity
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Undo < ActivityPub::Activity
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class ActivityPub::Activity::Update < ActivityPub::Activity
|
class ActivityPub
|
||||||
|
module Activity
|
||||||
|
class Update < ActivityPub::Activity
|
||||||
# Si estamos actualizando el objeto, tenemos que devolverlo a estado
|
# Si estamos actualizando el objeto, tenemos que devolverlo a estado
|
||||||
# de moderación
|
# de moderación
|
||||||
def update_activity_pub_state!
|
def update_activity_pub_state!
|
||||||
activity_pub.pause! if activity_pub.approved?
|
activity_pub.pause! if activity_pub.approved?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -5,10 +5,12 @@
|
||||||
# Actor es la entidad que realiza acciones en ActivityPub
|
# Actor es la entidad que realiza acciones en ActivityPub
|
||||||
#
|
#
|
||||||
# @todo Obtener el perfil dinámicamente
|
# @todo Obtener el perfil dinámicamente
|
||||||
class ActivityPub::Actor < ApplicationRecord
|
class ActivityPub
|
||||||
|
class Actor < ApplicationRecord
|
||||||
include ActivityPub::Concerns::JsonLdConcern
|
include ActivityPub::Concerns::JsonLdConcern
|
||||||
|
|
||||||
belongs_to :instance
|
belongs_to :instance
|
||||||
has_many :activity_pubs, as: :object
|
has_many :activity_pubs, as: :object
|
||||||
has_many :objects
|
has_many :objects
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
#
|
#
|
||||||
# Representa cada instancia del fediverso que interactúa con la Social
|
# Representa cada instancia del fediverso que interactúa con la Social
|
||||||
# Inbox.
|
# Inbox.
|
||||||
class ActivityPub::Instance < ApplicationRecord
|
class ActivityPub
|
||||||
|
class Instance < ApplicationRecord
|
||||||
include AASM
|
include AASM
|
||||||
|
|
||||||
validates :aasm_state, presence: true, inclusion: { in: %w[paused allowed blocked] }
|
validates :aasm_state, presence: true, inclusion: { in: %w[paused allowed blocked] }
|
||||||
|
@ -19,3 +20,4 @@ class ActivityPub::Instance < ApplicationRecord
|
||||||
state :blocked
|
state :blocked
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# Almacena objetos de ActivityPub, como Note, Article, etc.
|
# Almacena objetos de ActivityPub, como Note, Article, etc.
|
||||||
class ActivityPub::Object < ApplicationRecord
|
class ActivityPub
|
||||||
|
class Object < ApplicationRecord
|
||||||
include ActivityPub::Concerns::JsonLdConcern
|
include ActivityPub::Concerns::JsonLdConcern
|
||||||
|
|
||||||
belongs_to :actor
|
belongs_to :actor
|
||||||
|
@ -9,3 +10,4 @@ class ActivityPub::Object < ApplicationRecord
|
||||||
|
|
||||||
validates :actor_id, presence: true
|
validates :actor_id, presence: true
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
# = Application =
|
# = Application =
|
||||||
#
|
#
|
||||||
# Una aplicación o instancia
|
# Una aplicación o instancia
|
||||||
class ActivityPub::Object::Application < ActivityPub::Object; end
|
class ActivityPub
|
||||||
|
module Object
|
||||||
|
class Application < ActivityPub::Object; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
# = Article =
|
# = Article =
|
||||||
#
|
#
|
||||||
# Representa artículos
|
# Representa artículos
|
||||||
class ActivityPub::Object::Article < ActivityPub::Object; end
|
class ActivityPub
|
||||||
|
module Object
|
||||||
|
class Article < ActivityPub::Object; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# = Generic =
|
# = Generic =
|
||||||
class ActivityPub::Object::Generic < ActivityPub::Object; end
|
class ActivityPub
|
||||||
|
module Object
|
||||||
|
class Generic < ActivityPub::Object; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
# = Note =
|
# = Note =
|
||||||
#
|
#
|
||||||
# Representa notas, el tipo más común de objeto del Fediverso.
|
# 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
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
# = Organization =
|
# = Organization =
|
||||||
#
|
#
|
||||||
# Una organización
|
# Una organización
|
||||||
class ActivityPub::Object::Organization < ActivityPub::Object; end
|
class ActivityPub
|
||||||
|
module Object
|
||||||
|
class Organization < ActivityPub::Object; end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
# = Person =
|
# = Person =
|
||||||
#
|
#
|
||||||
# Una persona, el perfil de une actore
|
# 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
|
||||||
|
|
|
@ -69,8 +69,6 @@ class SocialInbox
|
||||||
#
|
#
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def generate_uri(&block)
|
def generate_uri(&block)
|
||||||
@public_key_url ||= URI("https://#{hostname}").tap do |uri|
|
@public_key_url ||= URI("https://#{hostname}").tap(&block).to_s
|
||||||
yield uri
|
|
||||||
end.to_s
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue