1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-29 01:44:53 +09:00

Web.ActivityPub: In MR, the 'object' of the 'Offer' is a 'Patch' URI

Instead of an 'OrderedCollection' of the versions
This commit is contained in:
fr33domlover 2020-07-14 11:10:43 +00:00
parent 216aaa72ee
commit 6d80b1e4f1
2 changed files with 33 additions and 39 deletions

View file

@ -112,9 +112,9 @@ getSharerPatchesR =
getSharerPatchR getSharerPatchR
:: ShrIdent -> KeyHashid TicketAuthorLocal -> Handler TypedContent :: ShrIdent -> KeyHashid TicketAuthorLocal -> Handler TypedContent
getSharerPatchR shr talkhid = do getSharerPatchR shr talkhid = do
(ticket, ptids, repo, massignee) <- runDB $ do (ticket, ptid, repo, massignee) <- runDB $ do
(_, _, Entity tid t, tp, ptids) <- getSharerPatch404 shr talkhid (_, _, Entity tid t, tp, ptid :| _) <- getSharerPatch404 shr talkhid
(,,,) t ptids (,,,) t ptid
<$> bitraverse <$> bitraverse
(\ (_, Entity _ trl) -> do (\ (_, Entity _ trl) -> do
r <- getJust $ ticketRepoLocalRepo trl r <- getJust $ ticketRepoLocalRepo trl
@ -141,8 +141,7 @@ getSharerPatchR shr talkhid = do
encodeRouteLocal <- getEncodeRouteLocal encodeRouteLocal <- getEncodeRouteLocal
encodeRouteHome <- getEncodeRouteHome encodeRouteHome <- getEncodeRouteHome
encodePatchId <- getEncodeKeyHashid encodePatchId <- getEncodeKeyHashid
let versionUrl = SharerPatchVersionR shr talkhid . encodePatchId let patchAP = AP.Ticket
patchAP = AP.Ticket
{ AP.ticketLocal = Just { AP.ticketLocal = Just
( hLocal ( hLocal
, AP.TicketLocal , AP.TicketLocal
@ -179,20 +178,24 @@ getSharerPatchR shr talkhid = do
encodeRouteHome . SharerR . sharerIdent <$> massignee encodeRouteHome . SharerR . sharerIdent <$> massignee
, AP.ticketIsResolved = ticketStatus ticket == TSClosed , AP.ticketIsResolved = ticketStatus ticket == TSClosed
, AP.ticketAttachment = Just , AP.ticketAttachment = Just
( hLocal ( case repo of
Left _ -> hLocal
Right (i, _) -> instanceHost i
, MergeRequest , MergeRequest
{ mrOrigin = Nothing { mrOrigin = Nothing
, mrTarget = , mrTarget =
case repo of case repo of
Left (s, r, Nothing) -> Left (s, r, Nothing) ->
encodeRouteHome $ encodeRouteLocal $
RepoR (sharerIdent s) (repoIdent r) RepoR (sharerIdent s) (repoIdent r)
Left (s, r, Just b) -> Left (s, r, Just b) ->
encodeRouteHome $ encodeRouteLocal $
RepoBranchR (sharerIdent s) (repoIdent r) b RepoBranchR (sharerIdent s) (repoIdent r) b
Right (i, ro) -> Right (_, ro) ->
ObjURI (instanceHost i) (remoteObjectIdent ro) remoteObjectIdent ro
, mrPatch = NE.map (encodeRouteLocal . versionUrl) ptids , mrPatch =
encodeRouteHome $ SharerPatchVersionR shr talkhid $
encodePatchId ptid
} }
) )
} }
@ -395,9 +398,9 @@ getRepoPatchesR shr rp = do
getRepoPatchR getRepoPatchR
:: ShrIdent -> RpIdent -> KeyHashid LocalTicket -> Handler TypedContent :: ShrIdent -> RpIdent -> KeyHashid LocalTicket -> Handler TypedContent
getRepoPatchR shr rp ltkhid = do getRepoPatchR shr rp ltkhid = do
(ticket, ptids, trl, author, massignee) <- runDB $ do (ticket, ptid, trl, author, massignee) <- runDB $ do
(_, _, Entity tid t, _, _, Entity _ trl, ta, ptids) <- getRepoPatch404 shr rp ltkhid (_, _, Entity tid t, _, _, Entity _ trl, ta, ptid :| _) <- getRepoPatch404 shr rp ltkhid
(,,,,) t ptids trl (,,,,) t ptid trl
<$> bitraverse <$> bitraverse
(\ (Entity _ tal, _) -> do (\ (Entity _ tal, _) -> do
p <- getJust $ ticketAuthorLocalAuthor tal p <- getJust $ ticketAuthorLocalAuthor tal
@ -418,8 +421,7 @@ getRepoPatchR shr rp ltkhid = do
encodeRouteLocal <- getEncodeRouteLocal encodeRouteLocal <- getEncodeRouteLocal
encodeRouteHome <- getEncodeRouteHome encodeRouteHome <- getEncodeRouteHome
encodePatchId <- getEncodeKeyHashid encodePatchId <- getEncodeKeyHashid
let versionUrl = RepoPatchVersionR shr rp ltkhid . encodePatchId let host =
host =
case author of case author of
Left _ -> hLocal Left _ -> hLocal
Right (i, _) -> instanceHost i Right (i, _) -> instanceHost i
@ -462,11 +464,13 @@ getRepoPatchR shr rp ltkhid = do
, MergeRequest , MergeRequest
{ mrOrigin = Nothing { mrOrigin = Nothing
, mrTarget = , mrTarget =
encodeRouteHome $ encodeRouteLocal $
case ticketRepoLocalBranch trl of case ticketRepoLocalBranch trl of
Nothing -> RepoR shr rp Nothing -> RepoR shr rp
Just b -> RepoBranchR shr rp b Just b -> RepoBranchR shr rp b
, mrPatch = NE.map (encodeRouteLocal . versionUrl) ptids , mrPatch =
encodeRouteHome $ RepoPatchVersionR shr rp ltkhid $
encodePatchId ptid
} }
) )
} }

View file

@ -958,8 +958,8 @@ encodeTicketLocal
data MergeRequest u = MergeRequest data MergeRequest u = MergeRequest
{ mrOrigin :: Maybe (ObjURI u) { mrOrigin :: Maybe (ObjURI u)
, mrTarget :: ObjURI u , mrTarget :: LocalURI
, mrPatch :: NonEmpty LocalURI , mrPatch :: ObjURI u
} }
instance ActivityPub MergeRequest where instance ActivityPub MergeRequest where
@ -969,30 +969,20 @@ instance ActivityPub MergeRequest where
typ <- o .: "type" typ <- o .: "type"
unless (typ == ("Offer" :: Text)) $ unless (typ == ("Offer" :: Text)) $
fail "type isn't Offer" fail "type isn't Offer"
(hPatch, patches) <- do
c <- o .: "object" ObjURI a target <- o .: "target"
ctyp <- c .: "type"
unless (ctyp == ("OrderedCollection" :: Text)) $ fmap (a,) $
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 MergeRequest
<$> o .:? "origin" <$> o .:? "origin"
<*> o .: "target" <*> pure target
<*> pure patches <*> o .: "object"
toSeries hPatch (MergeRequest morigin target patches) toSeries h (MergeRequest morigin target patch)
= "type" .= ("Offer" :: Text) = "type" .= ("Offer" :: Text)
<> "origin" .=? morigin <> "origin" .=? morigin
<> "target" .= target <> "target" .= ObjURI h target
<> "object" .= object <> "object" .= patch
[ "type" .= ("OrderedCollection" :: Text)
, "totalItems" .= length patches
, "orderedItems" .= NE.map (ObjURI hPatch) patches
]
data Ticket u = Ticket data Ticket u = Ticket
{ ticketLocal :: Maybe (Authority u, TicketLocal) { ticketLocal :: Maybe (Authority u, TicketLocal)