mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-19 02:36:21 +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!
|
||||
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!
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue