mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-27 18:24:51 +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:
parent
216aaa72ee
commit
6d80b1e4f1
2 changed files with 33 additions and 39 deletions
|
@ -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
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue