Add project outbox and outbox item routes

This commit is contained in:
fr33domlover 2019-06-16 21:37:31 +00:00
parent a65979f5af
commit e1ae75b50c
3 changed files with 58 additions and 14 deletions

View file

@ -96,6 +96,8 @@
/s/#ShrIdent/p/!new ProjectNewR GET
/s/#ShrIdent/p/#PrjIdent ProjectR GET PUT POST
/s/#ShrIdent/p/#PrjIdent/inbox ProjectInboxR GET POST
/s/#ShrIdent/p/#PrjIdent/outbox ProjectOutboxR GET
/s/#ShrIdent/p/#PrjIdent/outbox/#OutboxItemKeyHashid ProjectOutboxItemR GET
/s/#ShrIdent/p/#PrjIdent/team ProjectTeamR GET
/s/#ShrIdent/p/#PrjIdent/followers ProjectFollowersR GET
/s/#ShrIdent/p/#PrjIdent/edit ProjectEditR GET

View file

@ -808,6 +808,10 @@ instance YesodBreadcrumbs App where
, Just $ ProjectsR shar
)
ProjectInboxR shr prj -> ("Inbox", Just $ ProjectR shr prj)
ProjectOutboxR shr prj -> ("Outbox", Just $ ProjectR shr prj)
ProjectOutboxItemR shr prj hid -> ( "#" <> keyHashidText hid
, Just $ ProjectOutboxR shr prj
)
ProjectEditR shr prj -> ("Edit", Just $ ProjectR shr prj)
ProjectDevsR shr prj -> ( "Collaborators"
, Just $ ProjectR shr prj

View file

@ -23,6 +23,8 @@ module Vervis.Handler.Inbox
, getSharerOutboxR
, getSharerOutboxItemR
, postSharerOutboxR
, getProjectOutboxR
, getProjectOutboxItemR
, getActorKey1R
, getActorKey2R
, getNotificationsR
@ -367,16 +369,13 @@ getPublishR = do
((_result, widget), enctype) <- runFormPost activityForm
defaultLayout $ activityWidget shr widget enctype
getSharerOutboxR :: ShrIdent -> Handler TypedContent
getSharerOutboxR shr = do
getOutbox :: Route App -> AppDB OutboxId -> Handler TypedContent
getOutbox here getObid = do
(total, pages, mpage) <- runDB $ do
sid <- getKeyBy404 $ UniqueSharer shr
p <- getValBy404 $ UniquePersonIdent sid
let obid = personOutbox p
countAllItems = count [OutboxItemOutbox ==. obid]
obid <- getObid
let countAllItems = count [OutboxItemOutbox ==. obid]
selectItems off lim = selectList [OutboxItemOutbox ==. obid] [Desc OutboxItemId, OffsetBy off, LimitTo lim]
getPageAndNavCount countAllItems selectItems
let here = SharerOutboxR shr
encodeRouteLocal <- getEncodeRouteLocal
encodeRoutePageLocal <- getEncodeRoutePageLocal
let pageUrl = encodeRoutePageLocal here
@ -425,17 +424,37 @@ getSharerOutboxR shr = do
diffUTCTime now
defaultLayout $(widgetFile "person/outbox")
getSharerOutboxItemR :: ShrIdent -> KeyHashid OutboxItem -> Handler TypedContent
getSharerOutboxItemR shr obikhid = do
getOutboxItem
:: Route App
-> AppDB OutboxId
-> KeyHashid OutboxItem
-> Handler TypedContent
getOutboxItem here getObid obikhid = do
obiid <- decodeKeyHashid404 obikhid
Doc h act <- runDB $ do
obid <- getObid
obi <- get404 obiid
unless (outboxItemOutbox obi == obid) notFound
return $ persistJSONValue $ outboxItemActivity obi
provideHtmlAndAP' h act $ redirect (here, [("prettyjson", "true")])
getSharerOutboxR :: ShrIdent -> Handler TypedContent
getSharerOutboxR shr = getOutbox here getObid
where
here = SharerOutboxR shr
getObid = do
sid <- getKeyBy404 $ UniqueSharer shr
p <- getValBy404 $ UniquePersonIdent sid
obi <- get404 obiid
unless (outboxItemOutbox obi == personOutbox p) notFound
return $ persistJSONValue $ outboxItemActivity obi
let here = SharerOutboxItemR shr obikhid
provideHtmlAndAP' h act $ redirect (here, [("prettyjson", "true")])
return $ personOutbox p
getSharerOutboxItemR :: ShrIdent -> KeyHashid OutboxItem -> Handler TypedContent
getSharerOutboxItemR shr obikhid = getOutboxItem here getObid obikhid
where
here = SharerOutboxItemR shr obikhid
getObid = do
sid <- getKeyBy404 $ UniqueSharer shr
p <- getValBy404 $ UniquePersonIdent sid
return $ personOutbox p
postSharerOutboxR :: ShrIdent -> Handler Html
postSharerOutboxR shrAuthor = do
@ -488,6 +507,25 @@ postSharerOutboxR shrAuthor = do
setMessage $ toHtml $ "Message created! ID: " <> u
defaultLayout $ activityWidget shrAuthor widget enctype
getProjectOutboxR :: ShrIdent -> PrjIdent -> Handler TypedContent
getProjectOutboxR shr prj = getOutbox here getObid
where
here = ProjectOutboxR shr prj
getObid = do
sid <- getKeyBy404 $ UniqueSharer shr
j <- getValBy404 $ UniqueProject prj sid
return $ projectOutbox j
getProjectOutboxItemR
:: ShrIdent -> PrjIdent -> KeyHashid OutboxItem -> Handler TypedContent
getProjectOutboxItemR shr prj obikhid = getOutboxItem here getObid obikhid
where
here = ProjectOutboxItemR shr prj obikhid
getObid = do
sid <- getKeyBy404 $ UniqueSharer shr
j <- getValBy404 $ UniqueProject prj sid
return $ projectOutbox j
getActorKey :: ((ActorKey, ActorKey, Bool) -> ActorKey) -> Route App -> Handler TypedContent
getActorKey choose route = do
actorKey <-