Serve AS2 in getSharerInboxR

This commit is contained in:
fr33domlover 2019-05-21 00:14:49 +00:00
parent 7bcbe52274
commit 40d9a0990d

View file

@ -140,13 +140,54 @@ getInboxR = do
getSharerInboxR :: ShrIdent -> Handler TypedContent getSharerInboxR :: ShrIdent -> Handler TypedContent
getSharerInboxR shr = do getSharerInboxR shr = do
(_, _, items, navModel) <- getPageAndNavTop $ \ off lim -> runDB $ do (total, pages, mpage) <- runDB $ do
sid <- getKeyBy404 $ UniqueSharer shr sid <- getKeyBy404 $ UniqueSharer shr
pid <- getKeyBy404 $ UniquePersonIdent sid pid <- getKeyBy404 $ UniquePersonIdent sid
(,) <$> countItems pid getPageAndNavCount
<*> (map adaptItem <$> getItems pid off lim) (countItems pid)
(\ off lim -> map adaptItem <$> getItems pid off lim)
let here = OutboxR shr
encodeRouteLocal <- getEncodeRouteLocal
encodeRoutePageLocal <- getEncodeRoutePageLocal
let pageUrl = encodeRoutePageLocal here
host <- getsYesod $ appInstanceHost . appSettings
selectRep $
case mpage of
Nothing -> do
provideAP $ pure $ Doc host $ Collection
{ collectionId = encodeRouteLocal here
, collectionType = CollectionTypeOrdered
, collectionTotalItems = Just total
, collectionCurrent = Nothing
, collectionFirst = Just $ pageUrl 1
, collectionLast = Just $ pageUrl pages
, collectionItems = [] :: [Text]
}
provideRep (redirectFirstPage here :: Handler Html)
Just (items, navModel) -> do
let current = nmCurrent navModel
provideAP $ pure $ Doc host $ CollectionPage
{ collectionPageId = pageUrl current
, collectionPageType = CollectionPageTypeOrdered
, collectionPageTotalItems = Nothing
, collectionPageCurrent = Just $ pageUrl current
, collectionPageFirst = Just $ pageUrl 1
, collectionPageLast = Just $ pageUrl pages
, collectionPagePartOf = encodeRouteLocal here
, collectionPagePrev =
if current > 1
then Just $ pageUrl $ current - 1
else Nothing
, collectionPageNext =
if current < pages
then Just $ pageUrl $ current + 1
else Nothing
, collectionPageStartIndex = Nothing
, collectionPageItems = map fromEither items
}
provideRep $
let pageNav = navWidget navModel let pageNav = navWidget navModel
selectRep $ provideRep $ defaultLayout $(widgetFile "person/inbox") in defaultLayout $(widgetFile "person/inbox")
where where
countItems pid = countItems pid =
(+) <$> count [InboxItemLocalPerson ==. pid] (+) <$> count [InboxItemLocalPerson ==. pid]
@ -320,7 +361,7 @@ getOutboxR shr = do
encodeRoutePageLocal <- getEncodeRoutePageLocal encodeRoutePageLocal <- getEncodeRoutePageLocal
let pageUrl = encodeRoutePageLocal here let pageUrl = encodeRoutePageLocal here
host <- getsYesod $ appInstanceHost . appSettings host <- getsYesod $ appInstanceHost . appSettings
selectRep $ do selectRep $
case mpage of case mpage of
Nothing -> do Nothing -> do
provideAP $ pure $ Doc host $ Collection provideAP $ pure $ Doc host $ Collection