2024-02-20 17:44:52 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Almacena objetos de ActivityPub, como Note, Article, etc.
|
2024-02-21 15:46:38 +00:00
|
|
|
class ActivityPub
|
|
|
|
class Object < ApplicationRecord
|
|
|
|
include ActivityPub::Concerns::JsonLdConcern
|
2024-02-20 17:44:52 +00:00
|
|
|
|
2024-03-18 17:40:11 +00:00
|
|
|
before_validation :type_from_content!, unless: :type?
|
|
|
|
|
2024-03-06 20:15:21 +00:00
|
|
|
# Los objetos son únicos a toda la base de datos
|
2024-03-06 20:45:21 +00:00
|
|
|
validates :uri, presence: true, url: true, uniqueness: true
|
2024-03-06 20:15:21 +00:00
|
|
|
|
2024-02-21 15:46:38 +00:00
|
|
|
has_many :activity_pubs, as: :object
|
2024-02-24 16:04:52 +00:00
|
|
|
|
|
|
|
# Encontrar le Actor por su relación con el objeto
|
|
|
|
#
|
|
|
|
# @return [ActivityPub::Actor,nil]
|
|
|
|
def actor
|
2024-03-07 20:17:58 +00:00
|
|
|
ActivityPub::Actor.find_by(uri: actor_uri)
|
|
|
|
end
|
|
|
|
|
|
|
|
# @return [String]
|
|
|
|
def actor_uri
|
|
|
|
content['attributedTo']
|
2024-02-24 16:04:52 +00:00
|
|
|
end
|
2024-03-07 19:54:09 +00:00
|
|
|
|
|
|
|
def actor_type?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def object_type?
|
|
|
|
true
|
|
|
|
end
|
2024-03-18 14:55:38 +00:00
|
|
|
|
|
|
|
# Poder explorar propiedades remotas
|
|
|
|
#
|
|
|
|
# @return [DistributedPress::V1::Social::ReferencedObject]
|
|
|
|
def referenced(site)
|
|
|
|
require 'distributed_press/v1/social/referenced_object'
|
|
|
|
|
|
|
|
@referenced ||= DistributedPress::V1::Social::ReferencedObject.new(object: content, dereferencer: site.social_inbox.dereferencer)
|
|
|
|
end
|
2024-03-18 17:40:11 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Encuentra el tipo a partir del contenido, si existe.
|
|
|
|
#
|
|
|
|
# XXX: Si el objeto es una actividad, esto siempre va a ser
|
|
|
|
# Generic
|
|
|
|
def type_from_content!
|
|
|
|
self.type =
|
|
|
|
begin
|
|
|
|
"ActivityPub::Object::#{content['type'].presence || 'Generic'}".constantize
|
|
|
|
rescue NameError
|
|
|
|
ActivityPub::Object::Generic
|
|
|
|
end
|
|
|
|
end
|
2024-02-21 15:46:38 +00:00
|
|
|
end
|
2024-02-20 17:44:52 +00:00
|
|
|
end
|