From bad1844cfc421e1f1460a383435f09201022ae8d Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sun, 9 Jun 2019 16:45:53 +0000 Subject: [PATCH] Reuse the getSharerInboxR code to implement getProjectInboxR --- src/Vervis/Handler/Inbox.hs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Vervis/Handler/Inbox.hs b/src/Vervis/Handler/Inbox.hs index b76e997..a4e5d0d 100644 --- a/src/Vervis/Handler/Inbox.hs +++ b/src/Vervis/Handler/Inbox.hs @@ -143,16 +143,13 @@ getInboxR = do
#{decodeUtf8 body}
         |]
 
-getSharerInboxR :: ShrIdent -> Handler TypedContent
-getSharerInboxR shr = do
+getInbox :: Route App -> AppDB InboxId -> Handler TypedContent
+getInbox here getInboxId = do
     (total, pages, mpage) <- runDB $ do
-        sid <- getKeyBy404 $ UniqueSharer shr
-        p <- getValBy404 $ UniquePersonIdent sid
-        let ibid = personInbox p
+        ibid <- getInboxId
         getPageAndNavCount
             (countItems ibid)
             (\ off lim -> map adaptItem <$> getItems ibid off lim)
-    let here = SharerInboxR shr
     encodeRouteLocal <- getEncodeRouteLocal
     encodeRoutePageLocal <- getEncodeRoutePageLocal
     let pageUrl = encodeRoutePageLocal here
@@ -231,8 +228,23 @@ getSharerInboxR shr = do
             (Just act, Nothing) -> Left $ persistJSONValue act
             (Nothing, Just obj) -> Right $ persistJSONValue obj
 
+getSharerInboxR :: ShrIdent -> Handler TypedContent
+getSharerInboxR shr = getInbox here getInboxId
+    where
+    here = SharerInboxR shr
+    getInboxId = do
+        sid <- getKeyBy404 $ UniqueSharer shr
+        p <- getValBy404 $ UniquePersonIdent sid
+        return $ personInbox p
+
 getProjectInboxR :: ShrIdent -> PrjIdent -> Handler TypedContent
-getProjectInboxR _ _ = error "TODO implement getProjectInboxR"
+getProjectInboxR shr prj = getInbox here getInboxId
+    where
+    here = ProjectInboxR shr prj
+    getInboxId = do
+        sid <- getKeyBy404 $ UniqueSharer shr
+        j <- getValBy404 $ UniqueProject prj sid
+        return $ projectInbox j
 
 postSharerInboxR :: ShrIdent -> Handler ()
 postSharerInboxR shrRecip = do