-- eidolon -- A simple gallery in Haskell and Yesod
-- Copyright (C) 2015 Amedeo Molnár
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU Affero General Public License as published
-- by the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Affero General Public License for more details.
--
-- You should have received a copy of the GNU Affero General Public License
-- along with this program. If not, see
#{userSl} commented on your medium {mediumTitle medium}:
#{commentContent temp}
To follow the comment thread follow
this link
.
|]
setMessage "Your Comment has been posted"
redirect $ MediumR mediumId
_ -> do
setMessage "There has been an error whith your comment"
redirect $ MediumR mediumId
Nothing -> do
setMessage "You need to be looged in to comment on media"
redirect LoginR
Nothing -> do
setMessage "This image does not exist"
redirect HomeR
commentForm :: UserId -> MediumId -> Maybe CommentId -> AForm Handler Comment
commentForm authorId originId parentId = Comment
<$> pure authorId
<*> pure originId
<*> pure parentId
<*> lift (liftIO getCurrentTime)
<*> areq markdownField (bfs ("Comment this medium" :: T.Text)) Nothing
<* bootstrapSubmit ("Post comment" :: BootstrapSubmit Text)
getCommentReplyR :: CommentId -> Handler Html
getCommentReplyR commentId = do
tempComment <- runDB $ get commentId
case tempComment of
Just comment -> do
msu <- lookupSession "userId"
case msu of
Just tempUserId -> do
let userId = getUserIdFromText tempUserId
let mediumId = commentOrigin comment
parAuth <- runDB $ get $ commentAuthor comment
let parSlug = fromMaybe "" $ userSlug <$> parAuth
(replyWidget, enctype) <- generateFormPost $
renderBootstrap3 BootstrapBasicForm $
commentForm userId mediumId (Just commentId)
defaultLayout $ do
setTitle "Eidolon :: Reply to comment"
$(widgetFile "commentReply")
Nothing -> do
setMessage "You need to be logged in to comment on media"
redirect LoginR
Nothing -> do
setMessage "This comment does not Exist"
redirect HomeR
postCommentReplyR :: CommentId -> Handler Html
postCommentReplyR commentId = do
tempComment <- runDB $ get commentId
case tempComment of
Just comment -> do
msu <- lookupSession "userId"
case msu of
Just tempUserId -> do
let userId = getUserIdFromText tempUserId
u <- runDB $ getJust userId
let userSl = userSlug u
let mediumId = commentOrigin comment
((res, _), _) <- runFormPost $
renderBootstrap3 BootstrapBasicForm $
commentForm userId mediumId (Just commentId)
case res of
FormSuccess temp -> do
runDB $ insert_ temp
--send mail to parent author
parent <- runDB $ getJust $ fromJust $ commentParent temp
parAuth <- runDB $ getJust $ commentAuthor parent
link <- ($ MediumR (commentOrigin temp)) <$> getUrlRender
sendMail (userEmail parAuth) (userSl `T.append` " replied to your comment")
[shamlet|
#{userSl} replied to your comment:
#{commentContent temp}
To see the comment thread follow
this link
.
|]
--send mail to medium owner
medium <- runDB $ getJust mediumId
owner <- runDB $ getJust $ mediumOwner medium
sendMail (userEmail owner) (userSl `T.append` " commented on your medium")
[shamlet|
#{userSl} commented your medium with:
#{commentContent temp}
Hello #{userSlug parAuth}
Hello #{userSlug owner}