From 7a96d904f34ee8bdc93085909a5116c917aa3ebe Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Wed, 6 Nov 2019 20:46:21 +0000 Subject: [PATCH] Use `orderedItems` in `OrderedCollection` --- src/Web/ActivityPub.hs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Web/ActivityPub.hs b/src/Web/ActivityPub.hs index 58cf454..9617f46 100644 --- a/src/Web/ActivityPub.hs +++ b/src/Web/ActivityPub.hs @@ -466,7 +466,12 @@ instance (FromJSON a, ToJSON a) => ActivityPub (Collection a) where <> "current" .=? (ObjURI authority <$> curr) <> "first" .=? (PageURI authority <$> firzt) <> "last" .=? (PageURI authority <$> last) - <> "items" .=% items + <> itemsProp .=% items + where + itemsProp = + case typ of + CollectionTypeUnordered -> "items" + CollectionTypeOrdered -> "orderedItems" data CollectionPageType = CollectionPageTypeUnordered @@ -527,7 +532,12 @@ instance (FromJSON a, ToJSON a) => ActivityPub (CollectionPage a) where <> "prev" .=? (PageURI authority <$> prev) <> "next" .=? (PageURI authority <$> next) <> "startIndex" .=? ind - <> "items" .=% items + <> itemsProp .=% items + where + itemsProp = + case typ of + CollectionPageTypeUnordered -> "items" + CollectionPageTypeOrdered -> "orderedItems" data Recipient u = RecipientActor (Actor u) | RecipientCollection (Collection (ObjURI u) u) @@ -1133,7 +1143,7 @@ parsePush :: UriMode u => Authority u -> Object -> Parser (Push u) parsePush a o = do c <- o .: "object" Push - <$> (traverse (withAuthorityT a . parseObject) =<< c .: "items") + <$> (traverse (withAuthorityT a . parseObject) =<< c .: "items" <|> c .: "orderedItems") <*> (traverse (traverse $ withAuthorityT a . parseObject) =<< c .:? "earlyItems") <*> c .: "totalItems" <*> withAuthorityO a (o .: "target") @@ -1145,7 +1155,7 @@ encodePush :: UriMode u => Authority u -> Push u -> Series encodePush a (Push lateCommits earlyCommits total target context before after) = "object" `pair` pairs ( "type" .= ("OrderedCollection" :: Text) - <> pair "items" (objectList lateCommits) + <> pair "orderedItems" (objectList lateCommits) <> maybe mempty (pair "earlyItems" . objectList) earlyCommits <> "totalItems" .= total )