1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-28 23:44:51 +09:00

Use orderedItems in OrderedCollection

This commit is contained in:
fr33domlover 2019-11-06 20:46:21 +00:00
parent f8dd72d052
commit 7a96d904f3

View file

@ -466,7 +466,12 @@ instance (FromJSON a, ToJSON a) => ActivityPub (Collection a) where
<> "current" .=? (ObjURI authority <$> curr) <> "current" .=? (ObjURI authority <$> curr)
<> "first" .=? (PageURI authority <$> firzt) <> "first" .=? (PageURI authority <$> firzt)
<> "last" .=? (PageURI authority <$> last) <> "last" .=? (PageURI authority <$> last)
<> "items" .=% items <> itemsProp .=% items
where
itemsProp =
case typ of
CollectionTypeUnordered -> "items"
CollectionTypeOrdered -> "orderedItems"
data CollectionPageType data CollectionPageType
= CollectionPageTypeUnordered = CollectionPageTypeUnordered
@ -527,7 +532,12 @@ instance (FromJSON a, ToJSON a) => ActivityPub (CollectionPage a) where
<> "prev" .=? (PageURI authority <$> prev) <> "prev" .=? (PageURI authority <$> prev)
<> "next" .=? (PageURI authority <$> next) <> "next" .=? (PageURI authority <$> next)
<> "startIndex" .=? ind <> "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) 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 parsePush a o = do
c <- o .: "object" c <- o .: "object"
Push Push
<$> (traverse (withAuthorityT a . parseObject) =<< c .: "items") <$> (traverse (withAuthorityT a . parseObject) =<< c .: "items" <|> c .: "orderedItems")
<*> (traverse (traverse $ withAuthorityT a . parseObject) =<< c .:? "earlyItems") <*> (traverse (traverse $ withAuthorityT a . parseObject) =<< c .:? "earlyItems")
<*> c .: "totalItems" <*> c .: "totalItems"
<*> withAuthorityO a (o .: "target") <*> 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) encodePush a (Push lateCommits earlyCommits total target context before after)
= "object" `pair` pairs = "object" `pair` pairs
( "type" .= ("OrderedCollection" :: Text) ( "type" .= ("OrderedCollection" :: Text)
<> pair "items" (objectList lateCommits) <> pair "orderedItems" (objectList lateCommits)
<> maybe mempty (pair "earlyItems" . objectList) earlyCommits <> maybe mempty (pair "earlyItems" . objectList) earlyCommits
<> "totalItems" .= total <> "totalItems" .= total
) )