1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2025-01-10 11:26:45 +09:00
vervis/src/Vervis/Handler/Discussion.hs

47 lines
1.4 KiB
Haskell
Raw Normal View History

2016-05-20 01:58:23 +09:00
{- This file is part of Vervis.
-
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
-
- Copying is an act of love. Please copy, reuse and share.
-
- The author(s) have dedicated all copyright and related and neighboring
- rights to this software to the public domain worldwide. This software is
- distributed without any warranty.
-
- You should have received a copy of the CC0 Public Domain Dedication along
- with this software. If not, see
- <http://creativecommons.org/publicdomain/zero/1.0/>.
-}
module Vervis.Handler.Discussion
( getDiscussion
, getComment
)
where
import Prelude
import Control.Monad.IO.Class (liftIO)
import Data.Time.Clock (getCurrentTime)
import Database.Persist (Entity (..))
import Text.Blaze.Html (Html)
import Yesod.Core (defaultLayout)
import Yesod.Persist.Core (runDB, get404, getBy404)
import Vervis.Foundation (Handler)
import Vervis.Model
import Vervis.Widget.Discussion
getDiscussion :: DiscussionId -> Handler Html
getDiscussion did = defaultLayout $ discussionW did
getComment :: DiscussionId -> Int -> Handler Html
getComment did num = do
(msg, shr) <- runDB $ do
Entity _mid m <- getBy404 $ UniqueMessage did num
p <- get404 $ messageAuthor m
s <- get404 $ personIdent p
return (m, s)
now <- liftIO getCurrentTime
defaultLayout $ messageW shr (messageCreated msg) now (messageContent msg)