mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-14 23:24:55 +01:00
9110db41c5
* Federate pinned statuses over ActivityPub * Display pinned toots in web UI Fix #6117 * Fix migration * Fix tests * Update outbox_serializer.rb * Update remove_serializer.rb * Update add_serializer.rb * Update fetch_featured_collection_service.rb
41 lines
1.0 KiB
Ruby
41 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ActivityPub::CollectionSerializer < ActiveModel::Serializer
|
|
def self.serializer_for(model, options)
|
|
return ActivityPub::NoteSerializer if model.class.name == 'Status'
|
|
return ActivityPub::CollectionSerializer if model.class.name == 'ActivityPub::CollectionPresenter'
|
|
super
|
|
end
|
|
|
|
attributes :id, :type, :total_items
|
|
attribute :next, if: -> { object.next.present? }
|
|
attribute :prev, if: -> { object.prev.present? }
|
|
attribute :part_of, if: -> { object.part_of.present? }
|
|
|
|
has_one :first, if: -> { object.first.present? }
|
|
has_many :items, key: :items, if: -> { (!object.items.nil? || page?) && !ordered? }
|
|
has_many :items, key: :ordered_items, if: -> { (!object.items.nil? || page?) && ordered? }
|
|
|
|
def type
|
|
if page?
|
|
ordered? ? 'OrderedCollectionPage' : 'CollectionPage'
|
|
else
|
|
ordered? ? 'OrderedCollection' : 'Collection'
|
|
end
|
|
end
|
|
|
|
def total_items
|
|
object.size
|
|
end
|
|
|
|
private
|
|
|
|
def ordered?
|
|
object.type == :ordered
|
|
end
|
|
|
|
def page?
|
|
object.part_of.present?
|
|
end
|
|
end
|