5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-15 04:41:43 +00:00

fix: descubrir el tipo de objeto siempre

closes #15656

closes #15657

closes #15658

closes #15660

closes #15661

closes #15662

closes #15663

closes #15664

closes #15665

closes #15666

closes #15667

closes #15668

closes #15669

closes #15670

closes #15671

closes #15672

closes #15673

closes #15674

closes #15675

closes #15676

closes #15677

closes #15678

closes #15679

closes #15680

closes #15681

closes #15682

closes #15683

closes #15684

closes #15685

closes #15686

closes #15687

closes #15688

closes #15689

closes #15690

closes #15691

closes #15692

closes #15693

closes #15694

closes #15695

closes #15696

closes #15697

closes #15698

closes #15699

closes #15700

closes #15701

closes #15702

closes #15704

closes #15705

closes #15706

closes #15707

closes #15708
This commit is contained in:
f 2024-03-18 14:40:11 -03:00
parent bcfb7a5a7f
commit ceeb0009ef
No known key found for this signature in database
2 changed files with 18 additions and 12 deletions

View file

@ -64,18 +64,7 @@ class ActivityPub
# @return [ActivityPub::Object] # @return [ActivityPub::Object]
def object def object
@object ||= ::ActivityPub::Object.find_or_initialize_by(uri: object_uri).tap do |o| @object ||= ::ActivityPub::Object.find_or_initialize_by(uri: object_uri).tap do |o|
# XXX: Si el objeto es una actividad, esto siempre va a ser o.content = original_object if object_embedded?
# Generic
o.type ||= 'ActivityPub::Object::Generic'
if object_embedded?
o.content = original_object
begin
type = original_object[:type].presence
o.type = "ActivityPub::Object::#{type}".constantize if type
rescue NameError
end
end
o.save! o.save!

View file

@ -5,6 +5,8 @@ class ActivityPub
class Object < ApplicationRecord class Object < ApplicationRecord
include ActivityPub::Concerns::JsonLdConcern include ActivityPub::Concerns::JsonLdConcern
before_validation :type_from_content!, unless: :type?
# Los objetos son únicos a toda la base de datos # Los objetos son únicos a toda la base de datos
validates :uri, presence: true, url: true, uniqueness: true validates :uri, presence: true, url: true, uniqueness: true
@ -38,5 +40,20 @@ class ActivityPub
@referenced ||= DistributedPress::V1::Social::ReferencedObject.new(object: content, dereferencer: site.social_inbox.dereferencer) @referenced ||= DistributedPress::V1::Social::ReferencedObject.new(object: content, dereferencer: site.social_inbox.dereferencer)
end end
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
end end
end end