From 75c0bc0939c94103e5a7440c3b6509483c3d3eff Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Tue, 14 Jul 2020 11:25:37 +0000 Subject: [PATCH] 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. --- src/Vervis/Handler/Patch.hs | 10 ++++++---- src/Web/ActivityPub.hs | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Vervis/Handler/Patch.hs b/src/Vervis/Handler/Patch.hs index 0ad1ea4..213a0fa 100644 --- a/src/Vervis/Handler/Patch.hs +++ b/src/Vervis/Handler/Patch.hs @@ -194,8 +194,9 @@ getSharerPatchR shr talkhid = do Right (_, ro) -> remoteObjectIdent ro , mrPatch = - encodeRouteHome $ SharerPatchVersionR shr talkhid $ - encodePatchId ptid + Left $ encodeRouteHome $ + SharerPatchVersionR shr talkhid $ + encodePatchId ptid } ) } @@ -469,8 +470,9 @@ getRepoPatchR shr rp ltkhid = do Nothing -> RepoR shr rp Just b -> RepoBranchR shr rp b , mrPatch = - encodeRouteHome $ RepoPatchVersionR shr rp ltkhid $ - encodePatchId ptid + Left $ encodeRouteHome $ + RepoPatchVersionR shr rp ltkhid $ + encodePatchId ptid } ) } diff --git a/src/Web/ActivityPub.hs b/src/Web/ActivityPub.hs index 98a4b70..8cae27e 100644 --- a/src/Web/ActivityPub.hs +++ b/src/Web/ActivityPub.hs @@ -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)