mirror of
https://0xacab.org/sutty/sutty
synced 2025-02-21 16:11:48 +00:00
Merge branch 'issue-15109-1' of https://0xacab.org/sutty/sutty into production.panel.sutty.nl
This commit is contained in:
commit
01ef18297a
2 changed files with 18 additions and 12 deletions
|
@ -64,18 +64,7 @@ class ActivityPub
|
|||
# @return [ActivityPub::Object]
|
||||
def object
|
||||
@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
|
||||
# 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.content = original_object if object_embedded?
|
||||
|
||||
o.save!
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ class ActivityPub
|
|||
class Object < ApplicationRecord
|
||||
include ActivityPub::Concerns::JsonLdConcern
|
||||
|
||||
before_validation :type_from_content!, unless: :type?
|
||||
|
||||
# Los objetos son únicos a toda la base de datos
|
||||
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)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue