AP/AS serialization of Collections (#37434)
This commit is contained in:
1 parent
a4b8b9fe98
commit
a9cfddf28e
8 files changed
+139
No files matched your search
@@ -62,6 +62,8 @@ class ActivityPub::TagManager
|
||||
emoji_url(target)
|
||||
when :flag
|
||||
target.uri
|
||||
when :featured_collection
|
||||
ap_account_featured_collection_url(target.account.id, target)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -60,6 +60,10 @@ class Collection < ApplicationRecord
|
||||
self.tag = Tag.find_or_create_by_names(new_name).first
|
||||
end
|
||||
|
||||
def object_type
|
||||
:featured_collection
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def tag_is_usable
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ActivityPub::FeaturedCollectionSerializer < ActivityPub::Serializer
|
||||
class FeaturedItemSerializer < ActivityPub::Serializer
|
||||
attributes :type, :featured_object, :featured_object_type
|
||||
|
||||
def type
|
||||
'FeaturedItem'
|
||||
end
|
||||
|
||||
def featured_object
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def featured_object_type
|
||||
object.account.actor_type || 'Person'
|
||||
end
|
||||
end
|
||||
|
||||
attributes :id, :type, :total_items, :name, :summary, :attributed_to,
|
||||
:sensitive, :discoverable, :published, :updated
|
||||
|
||||
has_one :tag, key: :topic, serializer: ActivityPub::NoteSerializer::TagSerializer
|
||||
|
||||
has_many :collection_items, key: :ordered_items, serializer: FeaturedItemSerializer
|
||||
|
||||
def id
|
||||
ActivityPub::TagManager.instance.uri_for(object)
|
||||
end
|
||||
|
||||
def type
|
||||
'FeaturedCollection'
|
||||
end
|
||||
|
||||
def summary
|
||||
object.description
|
||||
end
|
||||
|
||||
def attributed_to
|
||||
ActivityPub::TagManager.instance.uri_for(object.account)
|
||||
end
|
||||
|
||||
def total_items
|
||||
object.collection_items.size
|
||||
end
|
||||
|
||||
def published
|
||||
object.created_at.iso8601
|
||||
end
|
||||
|
||||
def updated
|
||||
object.updated_at.iso8601
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user