diff --git a/src/Vervis/Handler/Patch.hs b/src/Vervis/Handler/Patch.hs index 58e891f..0ad1ea4 100644 --- a/src/Vervis/Handler/Patch.hs +++ b/src/Vervis/Handler/Patch.hs @@ -112,9 +112,9 @@ getSharerPatchesR = getSharerPatchR :: ShrIdent -> KeyHashid TicketAuthorLocal -> Handler TypedContent getSharerPatchR shr talkhid = do - (ticket, ptids, repo, massignee) <- runDB $ do - (_, _, Entity tid t, tp, ptids) <- getSharerPatch404 shr talkhid - (,,,) t ptids + (ticket, ptid, repo, massignee) <- runDB $ do + (_, _, Entity tid t, tp, ptid :| _) <- getSharerPatch404 shr talkhid + (,,,) t ptid <$> bitraverse (\ (_, Entity _ trl) -> do r <- getJust $ ticketRepoLocalRepo trl @@ -141,8 +141,7 @@ getSharerPatchR shr talkhid = do encodeRouteLocal <- getEncodeRouteLocal encodeRouteHome <- getEncodeRouteHome encodePatchId <- getEncodeKeyHashid - let versionUrl = SharerPatchVersionR shr talkhid . encodePatchId - patchAP = AP.Ticket + let patchAP = AP.Ticket { AP.ticketLocal = Just ( hLocal , AP.TicketLocal @@ -179,20 +178,24 @@ getSharerPatchR shr talkhid = do encodeRouteHome . SharerR . sharerIdent <$> massignee , AP.ticketIsResolved = ticketStatus ticket == TSClosed , AP.ticketAttachment = Just - ( hLocal + ( case repo of + Left _ -> hLocal + Right (i, _) -> instanceHost i , MergeRequest { mrOrigin = Nothing , mrTarget = case repo of Left (s, r, Nothing) -> - encodeRouteHome $ + encodeRouteLocal $ RepoR (sharerIdent s) (repoIdent r) Left (s, r, Just b) -> - encodeRouteHome $ + encodeRouteLocal $ RepoBranchR (sharerIdent s) (repoIdent r) b - Right (i, ro) -> - ObjURI (instanceHost i) (remoteObjectIdent ro) - , mrPatch = NE.map (encodeRouteLocal . versionUrl) ptids + Right (_, ro) -> + remoteObjectIdent ro + , mrPatch = + encodeRouteHome $ SharerPatchVersionR shr talkhid $ + encodePatchId ptid } ) } @@ -395,9 +398,9 @@ getRepoPatchesR shr rp = do getRepoPatchR :: ShrIdent -> RpIdent -> KeyHashid LocalTicket -> Handler TypedContent getRepoPatchR shr rp ltkhid = do - (ticket, ptids, trl, author, massignee) <- runDB $ do - (_, _, Entity tid t, _, _, Entity _ trl, ta, ptids) <- getRepoPatch404 shr rp ltkhid - (,,,,) t ptids trl + (ticket, ptid, trl, author, massignee) <- runDB $ do + (_, _, Entity tid t, _, _, Entity _ trl, ta, ptid :| _) <- getRepoPatch404 shr rp ltkhid + (,,,,) t ptid trl <$> bitraverse (\ (Entity _ tal, _) -> do p <- getJust $ ticketAuthorLocalAuthor tal @@ -418,8 +421,7 @@ getRepoPatchR shr rp ltkhid = do encodeRouteLocal <- getEncodeRouteLocal encodeRouteHome <- getEncodeRouteHome encodePatchId <- getEncodeKeyHashid - let versionUrl = RepoPatchVersionR shr rp ltkhid . encodePatchId - host = + let host = case author of Left _ -> hLocal Right (i, _) -> instanceHost i @@ -462,11 +464,13 @@ getRepoPatchR shr rp ltkhid = do , MergeRequest { mrOrigin = Nothing , mrTarget = - encodeRouteHome $ + encodeRouteLocal $ case ticketRepoLocalBranch trl of Nothing -> RepoR shr rp Just b -> RepoBranchR shr rp b - , mrPatch = NE.map (encodeRouteLocal . versionUrl) ptids + , mrPatch = + encodeRouteHome $ RepoPatchVersionR shr rp ltkhid $ + encodePatchId ptid } ) } diff --git a/src/Web/ActivityPub.hs b/src/Web/ActivityPub.hs index 2b83a7d..98a4b70 100644 --- a/src/Web/ActivityPub.hs +++ b/src/Web/ActivityPub.hs @@ -958,8 +958,8 @@ encodeTicketLocal data MergeRequest u = MergeRequest { mrOrigin :: Maybe (ObjURI u) - , mrTarget :: ObjURI u - , mrPatch :: NonEmpty LocalURI + , mrTarget :: LocalURI + , mrPatch :: ObjURI u } instance ActivityPub MergeRequest where @@ -969,30 +969,20 @@ instance ActivityPub MergeRequest where 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,) $ + + ObjURI a target <- o .: "target" + + fmap (a,) $ MergeRequest <$> o .:? "origin" - <*> o .: "target" - <*> pure patches + <*> pure target + <*> o .: "object" - toSeries hPatch (MergeRequest morigin target patches) + toSeries h (MergeRequest morigin target patch) = "type" .= ("Offer" :: Text) <> "origin" .=? morigin - <> "target" .= target - <> "object" .= object - [ "type" .= ("OrderedCollection" :: Text) - , "totalItems" .= length patches - , "orderedItems" .= NE.map (ObjURI hPatch) patches - ] + <> "target" .= ObjURI h target + <> "object" .= patch data Ticket u = Ticket { ticketLocal :: Maybe (Authority u, TicketLocal)