From 40d9a0990de62785f601e770e5faf1d7cf9d3a6a Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Tue, 21 May 2019 00:14:49 +0000 Subject: [PATCH] Serve AS2 in getSharerInboxR --- src/Vervis/Handler/Inbox.hs | 53 ++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/src/Vervis/Handler/Inbox.hs b/src/Vervis/Handler/Inbox.hs index 1a35980..dcac780 100644 --- a/src/Vervis/Handler/Inbox.hs +++ b/src/Vervis/Handler/Inbox.hs @@ -140,13 +140,54 @@ getInboxR = do getSharerInboxR :: ShrIdent -> Handler TypedContent getSharerInboxR shr = do - (_, _, items, navModel) <- getPageAndNavTop $ \ off lim -> runDB $ do + (total, pages, mpage) <- runDB $ do sid <- getKeyBy404 $ UniqueSharer shr pid <- getKeyBy404 $ UniquePersonIdent sid - (,) <$> countItems pid - <*> (map adaptItem <$> getItems pid off lim) - let pageNav = navWidget navModel - selectRep $ provideRep $ defaultLayout $(widgetFile "person/inbox") + getPageAndNavCount + (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 + in defaultLayout $(widgetFile "person/inbox") where countItems pid = (+) <$> count [InboxItemLocalPerson ==. pid] @@ -320,7 +361,7 @@ getOutboxR shr = do encodeRoutePageLocal <- getEncodeRoutePageLocal let pageUrl = encodeRoutePageLocal here host <- getsYesod $ appInstanceHost . appSettings - selectRep $ do + selectRep $ case mpage of Nothing -> do provideAP $ pure $ Doc host $ Collection