about summary refs log tree commit diff
path: root/app/serializers/activitypub/collection_serializer.rb
diff options
context:
space:
mode:
authorbeatrix <beatrix.bitrot@gmail.com>2017-09-28 21:48:28 -0400
committerGitHub <noreply@github.com>2017-09-28 21:48:28 -0400
commitc027a7bd4d7b5af21f4b201d656f7251fa3606a1 (patch)
treece2c2327b26358c26cb899ea918988af373ca6d6 /app/serializers/activitypub/collection_serializer.rb
parent210e6776fce016666ecfd248b2208c487f3440f9 (diff)
parent53f829dfa8bc376041a442dc84c22aa1cbfcb9d0 (diff)
Merge pull request #157 from glitch-soc/merging-upstream
ABRACA-HRRRRRRRRRRRNGGGGGGGHHH!!!!!!!!!!!!!!!!!!!
Diffstat (limited to 'app/serializers/activitypub/collection_serializer.rb')
-rw-r--r--app/serializers/activitypub/collection_serializer.rb25
1 files changed, 20 insertions, 5 deletions
diff --git a/app/serializers/activitypub/collection_serializer.rb b/app/serializers/activitypub/collection_serializer.rb
index d01dead28..9832133fc 100644
--- a/app/serializers/activitypub/collection_serializer.rb
+++ b/app/serializers/activitypub/collection_serializer.rb
@@ -3,23 +3,38 @@
 class ActivityPub::CollectionSerializer < ActiveModel::Serializer
   def self.serializer_for(model, options)
     return ActivityPub::ActivitySerializer 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_many :items, key: :ordered_items
+  has_one :first, if: -> { object.first.present? }
+  has_many :items, key: :items, if: -> { (object.items.present? || page?) && !ordered? }
+  has_many :items, key: :ordered_items, if: -> { (object.items.present? || page?) && ordered? }
 
   def type
-    case object.type
-    when :ordered
-      'OrderedCollection'
+    if page?
+      ordered? ? 'OrderedCollectionPage' : 'CollectionPage'
     else
-      'Collection'
+      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