mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-29 02:44:53 +09:00
S2S: Refactor projectOfferTicketF to use the new utils
This commit is contained in:
parent
58e88d1e1b
commit
1a8ecb5995
1 changed files with 117 additions and 201 deletions
|
@ -238,218 +238,134 @@ projectOfferTicketF
|
||||||
-> AP.Ticket URIMode
|
-> AP.Ticket URIMode
|
||||||
-> FedURI
|
-> FedURI
|
||||||
-> ExceptT Text Handler Text
|
-> ExceptT Text Handler Text
|
||||||
projectOfferTicketF
|
projectOfferTicketF now shrRecip prjRecip author body mfwd luOffer ticket uTarget = do
|
||||||
now shrRecip prjRecip author body mfwd luOffer ticket uTarget = do
|
(target, summary, content, source) <- checkOfferTicket author ticket uTarget
|
||||||
targetIsUs <- lift $ runExceptT checkTarget
|
mmhttp <- for (targetRelevance target) $ \ () -> lift $ runDB $ do
|
||||||
case targetIsUs of
|
Entity jid j <- do
|
||||||
Left t -> do
|
sid <- getKeyBy404 $ UniqueSharer shrRecip
|
||||||
logWarn $ T.concat
|
getBy404 $ UniqueProject prjRecip sid
|
||||||
[ recip, " got Offer Ticket with target "
|
mractid <- insertToInbox now author body (projectInbox j) luOffer False
|
||||||
, renderObjURI uTarget
|
for mractid $ \ ractid -> do
|
||||||
]
|
mremotesHttpFwd <- for mfwd $ \ (localRecips, sig) -> do
|
||||||
return t
|
let sieve =
|
||||||
Right () -> do
|
makeRecipientSet
|
||||||
hLocal <- getsYesod siteInstanceHost
|
[]
|
||||||
{-deps <- -}
|
[ LocalPersonCollectionProjectTeam shrRecip prjRecip
|
||||||
checkOffer ticket hLocal shrRecip prjRecip
|
, LocalPersonCollectionProjectFollowers shrRecip prjRecip
|
||||||
let colls =
|
]
|
||||||
findRelevantCollections shrRecip prjRecip hLocal $
|
remoteRecips <-
|
||||||
activityAudience $ actbActivity body
|
insertRemoteActivityToLocalInboxes
|
||||||
mremotesHttp <- runDBExcept $ do
|
False ractid $
|
||||||
(sid, jid, ibid, fsid{-, tids-}) <-
|
localRecipSieve'
|
||||||
getProjectAndDeps shrRecip prjRecip {-deps-}
|
sieve False False localRecips
|
||||||
lift $ do
|
(sig,) <$> deliverRemoteDB_J (actbBL body) ractid jid sig remoteRecips
|
||||||
mticket <- do
|
(obiidAccept, docAccept, fwdHostsAccept, recipsAccept) <- do
|
||||||
ra <- getJust $ remoteAuthorId author
|
obiidAccept <- insertEmptyOutboxItem (projectOutbox j) now
|
||||||
insertTicket ra luOffer jid ibid {-tids-}
|
ltid <- insertTicket now author jid summary content source ractid obiidAccept
|
||||||
for mticket $ \ (ractid, obiidAccept, docAccept) -> do
|
(docAccept, localRecipsAccept, remoteRecipsAccept, fwdHostsAccept) <-
|
||||||
msr <- for mfwd $ \ (_, sig) -> do
|
insertAccept shrRecip prjRecip author luOffer ltid obiidAccept
|
||||||
remoteRecips <- deliverFwdLocal ractid colls sid fsid
|
knownRemoteRecipsAccept <-
|
||||||
(sig,) <$> deliverRemoteDB_J (actbBL body) ractid jid sig remoteRecips
|
deliverLocal'
|
||||||
return (msr, obiidAccept, docAccept)
|
False
|
||||||
lift $ for_ mremotesHttp $ \ (msr, obiidAccept, docAccept) -> do
|
(LocalActorProject shrRecip prjRecip)
|
||||||
let handler e = logError $ "Project Accept sender: delivery failed! " <> T.pack (displayException e)
|
(projectInbox j)
|
||||||
for msr $ \ (sig, remotesHttp) -> do
|
obiidAccept
|
||||||
forkHandler handler $
|
localRecipsAccept
|
||||||
deliverRemoteHTTP_J now shrRecip prjRecip (actbBL body) sig remotesHttp
|
(obiidAccept,docAccept,fwdHostsAccept,) <$>
|
||||||
forkHandler handler $ publishAccept luOffer obiidAccept docAccept
|
deliverRemoteDB'' fwdHostsAccept obiidAccept remoteRecipsAccept knownRemoteRecipsAccept
|
||||||
return $ recip <> " inserted new ticket"
|
return (mremotesHttpFwd, obiidAccept, docAccept, fwdHostsAccept, recipsAccept)
|
||||||
|
case mmhttp of
|
||||||
|
Nothing -> return "Offer target isn't me, not using"
|
||||||
|
Just mhttp ->
|
||||||
|
case mhttp of
|
||||||
|
Nothing -> return "Activity already in my inbox, doing nothing"
|
||||||
|
Just (mremotesHttpFwd, obiid, doc, fwdHosts, remotes) -> do
|
||||||
|
for_ mremotesHttpFwd $ \ (sig, remotes) ->
|
||||||
|
forkWorker "projectOfferTicketF inbox-forwarding" $
|
||||||
|
deliverRemoteHTTP_J now shrRecip prjRecip (actbBL body) sig remotes
|
||||||
|
forkWorker "projectOfferTicketF Accept HTTP delivery" $
|
||||||
|
deliverRemoteHttp' fwdHosts obiid doc remotes
|
||||||
|
return $
|
||||||
|
case mremotesHttpFwd of
|
||||||
|
Nothing -> "Accepted new ticket, no inbox-forwarding to do"
|
||||||
|
Just _ -> "Accepted new ticket and ran inbox-forwarding of the Offer"
|
||||||
where
|
where
|
||||||
recip = T.concat ["/s/", shr2text shrRecip, "/p/", prj2text prjRecip]
|
targetRelevance (Left (shr, prj))
|
||||||
checkTarget = do
|
| shr == shrRecip && prj == prjRecip = Just ()
|
||||||
let ObjURI h lu = uTarget
|
targetRelevance _ = Nothing
|
||||||
local <- hostIsLocal h
|
insertTicket now author jid summary content source ractidOffer obiidAccept = do
|
||||||
unless local $
|
did <- insert Discussion
|
||||||
throwE $ recip <> " not using; target has different host"
|
fsid <- insert FollowerSet
|
||||||
route <-
|
tid <- insert Ticket
|
||||||
case decodeRouteLocal lu of
|
{ ticketNumber = Nothing
|
||||||
Nothing ->
|
, ticketCreated = now
|
||||||
throwE $
|
, ticketTitle = unTextHtml summary
|
||||||
recip <> " not using; local target isn't a valid route"
|
, ticketSource = unTextPandocMarkdown source
|
||||||
Just r -> return r
|
, ticketDescription = unTextHtml content
|
||||||
(shrTarget, prjTarget) <-
|
, ticketAssignee = Nothing
|
||||||
case route of
|
, ticketStatus = TSNew
|
||||||
ProjectR shr prj -> return (shr, prj)
|
, ticketClosed = UTCTime (ModifiedJulianDay 0) 0
|
||||||
_ -> throwE $
|
, ticketCloser = Nothing
|
||||||
recip <>
|
|
||||||
" not using; local target isn't a project route"
|
|
||||||
unless (shrTarget == shrRecip && prjTarget == prjRecip) $
|
|
||||||
throwE $ recip <> " not using; local target is a different project"
|
|
||||||
insertTicket ra luOffer jid ibid {-deps-} = do
|
|
||||||
let iidAuthor = remoteAuthorInstance author
|
|
||||||
roid <-
|
|
||||||
either entityKey id <$> insertBy' (RemoteObject iidAuthor luOffer)
|
|
||||||
let raidAuthor = remoteAuthorId author
|
|
||||||
ractid <- either entityKey id <$> insertBy' RemoteActivity
|
|
||||||
{ remoteActivityIdent = roid
|
|
||||||
, remoteActivityContent = persistJSONFromBL $ actbBL body
|
|
||||||
, remoteActivityReceived = now
|
|
||||||
}
|
}
|
||||||
ibiid <- insert $ InboxItem False
|
ltid <- insert LocalTicket
|
||||||
mibirid <- insertUnique $ InboxItemRemote ibid ractid ibiid
|
{ localTicketTicket = tid
|
||||||
case mibirid of
|
, localTicketDiscuss = did
|
||||||
Nothing -> do
|
, localTicketFollowers = fsid
|
||||||
delete ibiid
|
}
|
||||||
return Nothing
|
tclid <- insert TicketContextLocal
|
||||||
Just _ibirid -> do
|
{ ticketContextLocalTicket = tid
|
||||||
{-
|
, ticketContextLocalAccept = obiidAccept
|
||||||
next <-
|
}
|
||||||
((subtract 1) . projectNextTicket) <$>
|
insert_ TicketProjectLocal
|
||||||
updateGet jid [ProjectNextTicket +=. 1]
|
{ ticketProjectLocalContext = tclid
|
||||||
-}
|
, ticketProjectLocalProject = jid
|
||||||
did <- insert Discussion
|
}
|
||||||
fsid <- insert FollowerSet
|
insert_ TicketAuthorRemote
|
||||||
|
{ ticketAuthorRemoteTicket = tclid
|
||||||
obiidAccept <- do
|
, ticketAuthorRemoteAuthor = remoteAuthorId author
|
||||||
obidProject <- do
|
, ticketAuthorRemoteOpen = ractidOffer
|
||||||
sid <- fromJust <$> getKeyBy (UniqueSharer shrRecip)
|
}
|
||||||
j <- fromJust <$> getValBy (UniqueProject prjRecip sid)
|
return ltid
|
||||||
return $ projectOutbox j
|
insertAccept shr prj author luOffer ltid obiidAccept = do
|
||||||
hLocal <- asksSite siteInstanceHost
|
|
||||||
now <- liftIO getCurrentTime
|
|
||||||
insert OutboxItem
|
|
||||||
{ outboxItemOutbox = obidProject
|
|
||||||
, outboxItemActivity = persistJSONObjectFromDoc $ Doc hLocal emptyActivity
|
|
||||||
, outboxItemPublished = now
|
|
||||||
}
|
|
||||||
|
|
||||||
tid <- insert Ticket
|
|
||||||
{ ticketNumber = Nothing
|
|
||||||
, ticketCreated = now
|
|
||||||
, ticketTitle = unTextHtml $ AP.ticketSummary ticket
|
|
||||||
, ticketSource =
|
|
||||||
unTextPandocMarkdown $ AP.ticketSource ticket
|
|
||||||
, ticketDescription = unTextHtml $ AP.ticketContent ticket
|
|
||||||
, ticketAssignee = Nothing
|
|
||||||
, ticketStatus = TSNew
|
|
||||||
, ticketClosed = UTCTime (ModifiedJulianDay 0) 0
|
|
||||||
, ticketCloser = Nothing
|
|
||||||
}
|
|
||||||
ltid <- insert LocalTicket
|
|
||||||
{ localTicketTicket = tid
|
|
||||||
, localTicketDiscuss = did
|
|
||||||
, localTicketFollowers = fsid
|
|
||||||
}
|
|
||||||
tclid <- insert TicketContextLocal
|
|
||||||
{ ticketContextLocalTicket = tid
|
|
||||||
, ticketContextLocalAccept = obiidAccept
|
|
||||||
}
|
|
||||||
insert_ TicketProjectLocal
|
|
||||||
{ ticketProjectLocalContext = tclid
|
|
||||||
, ticketProjectLocalProject = jid
|
|
||||||
}
|
|
||||||
insert_ TicketAuthorRemote
|
|
||||||
{ ticketAuthorRemoteTicket = tclid
|
|
||||||
, ticketAuthorRemoteAuthor = raidAuthor
|
|
||||||
, ticketAuthorRemoteOpen = ractid
|
|
||||||
}
|
|
||||||
docAccept <- insertAccept ra luOffer ltid obiidAccept
|
|
||||||
-- insertMany_ $ map (TicketDependency tid) deps
|
|
||||||
--insert_ $ RemoteFollow raidAuthor fsid False True
|
|
||||||
return $ Just (ractid, obiidAccept, docAccept)
|
|
||||||
|
|
||||||
insertAccept ra luOffer ltid obiid = do
|
|
||||||
let uAuthor@(ObjURI hAuthor luAuthor) = remoteAuthorURI author
|
|
||||||
ltkhid <- encodeKeyHashid ltid
|
|
||||||
summary <-
|
|
||||||
TextHtml . TL.toStrict . renderHtml <$>
|
|
||||||
withUrlRenderer
|
|
||||||
[hamlet|
|
|
||||||
<p>
|
|
||||||
<a href="#{renderObjURI uAuthor}">
|
|
||||||
$maybe name <- remoteActorName ra
|
|
||||||
#{name}
|
|
||||||
$nothing
|
|
||||||
#{renderAuthority hAuthor}#{localUriPath luAuthor}
|
|
||||||
\'s ticket accepted by project #
|
|
||||||
<a href=@{ProjectR shrRecip prjRecip}>
|
|
||||||
./s/#{shr2text shrRecip}/p/#{prj2text prjRecip}
|
|
||||||
\: #
|
|
||||||
<a href=@{ProjectTicketR shrRecip prjRecip ltkhid}>
|
|
||||||
#{preEscapedToHtml $ unTextHtml $ AP.ticketSummary ticket}.
|
|
||||||
|]
|
|
||||||
hLocal <- asksSite siteInstanceHost
|
|
||||||
encodeRouteLocal <- getEncodeRouteLocal
|
encodeRouteLocal <- getEncodeRouteLocal
|
||||||
encodeRouteHome <- getEncodeRouteHome
|
encodeRouteHome <- getEncodeRouteHome
|
||||||
obikhid <- encodeKeyHashid obiid
|
|
||||||
let recips =
|
hLocal <- asksSite siteInstanceHost
|
||||||
remoteAuthorURI author :
|
|
||||||
map encodeRouteHome
|
obikhidAccept <- encodeKeyHashid obiidAccept
|
||||||
[ ProjectTeamR shrRecip prjRecip
|
ltkhid <- encodeKeyHashid ltid
|
||||||
, ProjectFollowersR shrRecip prjRecip
|
|
||||||
|
ra <- getJust $ remoteAuthorId author
|
||||||
|
|
||||||
|
let ObjURI hAuthor luAuthor = remoteAuthorURI author
|
||||||
|
|
||||||
|
audAuthor =
|
||||||
|
AudRemote hAuthor [luAuthor] (maybeToList $ remoteActorFollowers ra)
|
||||||
|
audProject =
|
||||||
|
AudLocal []
|
||||||
|
[ LocalPersonCollectionProjectTeam shr prj
|
||||||
|
, LocalPersonCollectionProjectFollowers shr prj
|
||||||
]
|
]
|
||||||
|
|
||||||
|
(recipientSet, remoteActors, fwdHosts, audLocal, audRemote) =
|
||||||
|
collectAudience [audAuthor, audProject]
|
||||||
|
|
||||||
|
recips = map encodeRouteHome audLocal ++ audRemote
|
||||||
doc = Doc hLocal Activity
|
doc = Doc hLocal Activity
|
||||||
{ activityId =
|
{ activityId =
|
||||||
Just $ encodeRouteLocal $
|
Just $ encodeRouteLocal $
|
||||||
ProjectOutboxItemR shrRecip prjRecip obikhid
|
ProjectOutboxItemR shr prj obikhidAccept
|
||||||
, activityActor =
|
, activityActor = encodeRouteLocal $ ProjectR shr prj
|
||||||
encodeRouteLocal $ ProjectR shrRecip prjRecip
|
, activitySummary = Nothing
|
||||||
, activitySummary = Just summary
|
|
||||||
, activityAudience = Audience recips [] [] [] [] []
|
, activityAudience = Audience recips [] [] [] [] []
|
||||||
, activitySpecific = AcceptActivity Accept
|
, activitySpecific = AcceptActivity Accept
|
||||||
{ acceptObject =
|
{ acceptObject = ObjURI hAuthor luOffer
|
||||||
ObjURI
|
|
||||||
(objUriAuthority $ remoteAuthorURI author)
|
|
||||||
luOffer
|
|
||||||
, acceptResult =
|
, acceptResult =
|
||||||
Just $ encodeRouteLocal $
|
Just $ encodeRouteLocal $ ProjectTicketR shr prj ltkhid
|
||||||
ProjectTicketR shrRecip prjRecip ltkhid
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update obiid [OutboxItemActivity =. persistJSONObjectFromDoc doc]
|
update obiidAccept [OutboxItemActivity =. persistJSONObjectFromDoc doc]
|
||||||
return doc
|
return (doc, recipientSet, remoteActors, fwdHosts)
|
||||||
|
|
||||||
publishAccept luOffer obiid doc = do
|
|
||||||
now <- liftIO getCurrentTime
|
|
||||||
let dont = Authority "dont-do.any-forwarding" Nothing
|
|
||||||
remotesHttp <- runDB $ do
|
|
||||||
(sid, project) <- do
|
|
||||||
sid <- fromJust <$> getKeyBy (UniqueSharer shrRecip)
|
|
||||||
j <- fromJust <$> getValBy (UniqueProject prjRecip sid)
|
|
||||||
return (sid, j)
|
|
||||||
moreRemotes <- deliverLocal now sid (projectFollowers project) obiid
|
|
||||||
let raidAuthor = remoteAuthorId author
|
|
||||||
ra <- getJust raidAuthor
|
|
||||||
ro <- getJust $ remoteActorIdent ra
|
|
||||||
let raInfo = RemoteRecipient raidAuthor (remoteObjectIdent ro) (remoteActorInbox ra) (remoteActorErrorSince ra)
|
|
||||||
iidAuthor = remoteAuthorInstance author
|
|
||||||
hAuthor = objUriAuthority $ remoteAuthorURI author
|
|
||||||
hostSection = ((iidAuthor, hAuthor), raInfo :| [])
|
|
||||||
remotes = unionRemotes [hostSection] moreRemotes
|
|
||||||
deliverRemoteDB' dont obiid [] remotes
|
|
||||||
site <- askSite
|
|
||||||
liftIO $ runWorker (deliverRemoteHttp dont obiid doc remotesHttp) site
|
|
||||||
where
|
|
||||||
deliverLocal now sid fsid obiid = do
|
|
||||||
(pidsTeam, remotesTeam) <- getProjectTeam sid
|
|
||||||
(pidsFollowers, remotesFollowers) <- getFollowers fsid
|
|
||||||
let pids = LO.union pidsTeam pidsFollowers
|
|
||||||
remotes = unionRemotes remotesTeam remotesFollowers
|
|
||||||
for_ pids $ \ pid -> do
|
|
||||||
ibid <- personInbox <$> getJust pid
|
|
||||||
ibiid <- insert $ InboxItem True
|
|
||||||
insert_ $ InboxItemLocal ibid obiid ibiid
|
|
||||||
return remotes
|
|
||||||
|
|
||||||
checkCreateTicket
|
checkCreateTicket
|
||||||
:: RemoteAuthor
|
:: RemoteAuthor
|
||||||
|
@ -1159,7 +1075,7 @@ projectOfferDepF now shrRecip prjRecip author body mfwd luOffer dep uTarget = do
|
||||||
doc = Doc hLocal Activity
|
doc = Doc hLocal Activity
|
||||||
{ activityId =
|
{ activityId =
|
||||||
Just $ encodeRouteLocal $
|
Just $ encodeRouteLocal $
|
||||||
SharerOutboxItemR shrRecip obikhidAccept
|
ProjectOutboxItemR shrRecip prjRecip obikhidAccept
|
||||||
, activityActor = encodeRouteLocal $ ProjectR shrRecip prjRecip
|
, activityActor = encodeRouteLocal $ ProjectR shrRecip prjRecip
|
||||||
, activitySummary = Nothing
|
, activitySummary = Nothing
|
||||||
, activityAudience = Audience recips [] [] [] [] []
|
, activityAudience = Audience recips [] [] [] [] []
|
||||||
|
@ -1320,7 +1236,7 @@ repoOfferDepF now shrRecip rpRecip author body mfwd luOffer dep uTarget = do
|
||||||
doc = Doc hLocal Activity
|
doc = Doc hLocal Activity
|
||||||
{ activityId =
|
{ activityId =
|
||||||
Just $ encodeRouteLocal $
|
Just $ encodeRouteLocal $
|
||||||
SharerOutboxItemR shrRecip obikhidAccept
|
RepoOutboxItemR shrRecip rpRecip obikhidAccept
|
||||||
, activityActor = encodeRouteLocal $ RepoR shrRecip rpRecip
|
, activityActor = encodeRouteLocal $ RepoR shrRecip rpRecip
|
||||||
, activitySummary = Nothing
|
, activitySummary = Nothing
|
||||||
, activityAudience = Audience recips [] [] [] [] []
|
, activityAudience = Audience recips [] [] [] [] []
|
||||||
|
|
Loading…
Reference in a new issue