{- This file is part of Vervis. - - Written in 2016 by fr33domlover . - - ♡ 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 - . -} 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)