1
0
Fork 0
mirror of https://code.naskya.net/repos/ndqEd synced 2025-03-20 15:14:54 +09:00

AP: In getSharerPatchR, provide the list of patch versions, latest first

This commit is contained in:
fr33domlover 2020-05-25 12:39:25 +00:00
parent c63479470e
commit 17e59af1c4
9 changed files with 92 additions and 9 deletions

View file

@ -49,6 +49,7 @@ module Web.ActivityPub
, PatchType (..)
, Patch (..)
, TicketLocal (..)
, MergeRequest (..)
, Ticket (..)
, Author (..)
, Hash (..)
@ -924,6 +925,44 @@ encodeTicketLocal
<> "dependencies" .= ObjURI a deps
<> "dependants" .= ObjURI a rdeps
data MergeRequest u = MergeRequest
{ mrOrigin :: Maybe (ObjURI u)
, mrTarget :: ObjURI u
, mrPatch :: NonEmpty LocalURI
}
instance ActivityPub MergeRequest where
jsonldContext _ = [as2Context, forgeContext]
parseObject o = do
typ <- o .: "type"
unless (typ == ("Offer" :: Text)) $
fail "type isn't Offer"
(hPatch, patches) <- do
c <- o .: "object"
ctyp <- c .: "type"
unless (ctyp == ("OrderedCollection" :: Text)) $
fail "type isn't OrderedCollection"
ObjURI h lu :| us <- c .: "items" <|> c .: "orderedItems"
let (hs, lus) = unzip $ map (\ (ObjURI h lu) -> (h, lu)) us
unless (all (== h) hs) $ fail "Version hosts differ"
return (h, lu :| lus)
fmap (hPatch,) $
MergeRequest
<$> o .:? "origin"
<*> o .: "target"
<*> pure patches
toSeries hPatch (MergeRequest morigin target patches)
= "type" .= ("Offer" :: Text)
<> "origin" .=? morigin
<> "target" .= target
<> "object" .= object
[ "type" .= ("OrderedCollection" :: Text)
, "totalItems" .= length patches
, "orderedItems" .= NE.map (ObjURI hPatch) patches
]
data Ticket u = Ticket
{ ticketLocal :: Maybe (Authority u, TicketLocal)
, ticketAttributedTo :: LocalURI
@ -936,6 +975,7 @@ data Ticket u = Ticket
, ticketSource :: TextPandocMarkdown
, ticketAssignedTo :: Maybe (ObjURI u)
, ticketIsResolved :: Bool
, ticketAttachment :: Maybe (Authority u, MergeRequest u)
}
instance ActivityPub Ticket where
@ -969,10 +1009,11 @@ instance ActivityPub Ticket where
<*> source .: "content"
<*> o .:? "assignedTo"
<*> o .: "isResolved"
<*> (traverse parseObject =<< o .:? "attachment")
toSeries authority
(Ticket local attributedTo published updated context {-name-}
summary content source assignedTo isResolved)
summary content source assignedTo isResolved mmr)
= maybe mempty (uncurry encodeTicketLocal) local
<> "type" .= ("Ticket" :: Text)
@ -990,6 +1031,10 @@ instance ActivityPub Ticket where
]
<> "assignedTo" .=? assignedTo
<> "isResolved" .= isResolved
<> maybe
mempty
(\ (h, mr) -> "attachment" `pair` pairs (toSeries h mr))
mmr
data Author = Author
{ authorName :: Text