Web.ActivityPub: Ticket attachment's Offer object can be either URI or a Patch

This will allow to use this representation for Offer and Create activities.
When creating a new MR, the inner Offer's 'object' is a 'Patch' object. When
serving an existing hosted MR, the inner Offer's 'object' is just a URI
pointing to the patch.
This commit is contained in:
fr33domlover 2020-07-14 11:25:37 +00:00
parent 6d80b1e4f1
commit 75c0bc0939
2 changed files with 11 additions and 7 deletions

View file

@ -194,7 +194,8 @@ getSharerPatchR shr talkhid = do
Right (_, ro) ->
remoteObjectIdent ro
, mrPatch =
encodeRouteHome $ SharerPatchVersionR shr talkhid $
Left $ encodeRouteHome $
SharerPatchVersionR shr talkhid $
encodePatchId ptid
}
)
@ -469,7 +470,8 @@ getRepoPatchR shr rp ltkhid = do
Nothing -> RepoR shr rp
Just b -> RepoBranchR shr rp b
, mrPatch =
encodeRouteHome $ RepoPatchVersionR shr rp ltkhid $
Left $ encodeRouteHome $
RepoPatchVersionR shr rp ltkhid $
encodePatchId ptid
}
)

View file

@ -959,7 +959,7 @@ encodeTicketLocal
data MergeRequest u = MergeRequest
{ mrOrigin :: Maybe (ObjURI u)
, mrTarget :: LocalURI
, mrPatch :: ObjURI u
, mrPatch :: Either (ObjURI u) (Authority u, Patch u)
}
instance ActivityPub MergeRequest where
@ -976,13 +976,15 @@ instance ActivityPub MergeRequest where
MergeRequest
<$> o .:? "origin"
<*> pure target
<*> o .: "object"
<*> (second fromDoc . toEither <$> o .: "object")
where
fromDoc (Doc h v) = (h, v)
toSeries h (MergeRequest morigin target patch)
= "type" .= ("Offer" :: Text)
<> "origin" .=? morigin
<> "target" .= ObjURI h target
<> "object" .= patch
<> "object" .= fromEither (second (uncurry Doc) patch)
data Ticket u = Ticket
{ ticketLocal :: Maybe (Authority u, TicketLocal)