The code powering m.abunchtell.com https://m.abunchtell.com
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

46 рядки
1.2 KiB

  1. # frozen_string_literal: true
  2. class ActivityPub::CollectionSerializer < ActivityPub::Serializer
  3. def self.serializer_for(model, options)
  4. return ActivityPub::NoteSerializer if model.class.name == 'Status'
  5. return ActivityPub::CollectionSerializer if model.class.name == 'ActivityPub::CollectionPresenter'
  6. super
  7. end
  8. cache key: 'collection', expires_in: 3.minutes
  9. attribute :id, if: -> { object.id.present? }
  10. attribute :type
  11. attribute :total_items, if: -> { object.size.present? }
  12. attribute :next, if: -> { object.next.present? }
  13. attribute :prev, if: -> { object.prev.present? }
  14. attribute :part_of, if: -> { object.part_of.present? }
  15. has_one :first, if: -> { object.first.present? }
  16. has_one :last, if: -> { object.last.present? }
  17. has_many :items, key: :items, if: -> { (!object.items.nil? || page?) && !ordered? }
  18. has_many :items, key: :ordered_items, if: -> { (!object.items.nil? || page?) && ordered? }
  19. def type
  20. if page?
  21. ordered? ? 'OrderedCollectionPage' : 'CollectionPage'
  22. else
  23. ordered? ? 'OrderedCollection' : 'Collection'
  24. end
  25. end
  26. def total_items
  27. object.size
  28. end
  29. private
  30. def ordered?
  31. object.type == :ordered
  32. end
  33. def page?
  34. object.part_of.present? || object.page.present?
  35. end
  36. end