From 732349a6d14d2b5d7aa0b3a73b114f257ab8c479 Mon Sep 17 00:00:00 2001 From: nek0 Date: Sat, 6 Dec 2014 14:02:19 +0100 Subject: [PATCH] added email notofocation on album share --- Handler/AlbumSettings.hs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Handler/AlbumSettings.hs b/Handler/AlbumSettings.hs index 154304f..324fb0e 100644 --- a/Handler/AlbumSettings.hs +++ b/Handler/AlbumSettings.hs @@ -4,6 +4,7 @@ import Import import qualified Data.Text as T import System.Directory import System.FilePath +import qualified Data.List as L getAlbumSettingsR :: AlbumId -> Handler Html getAlbumSettingsR albumId = do @@ -58,9 +59,27 @@ postAlbumSettingsR albumId = do ((result, albumSettingsWidget), enctype) <- runFormPost $ albumSettingsForm album albumId users case result of FormSuccess temp -> do + newShares <- return (L.sort $ albumShares temp) + oldShares <- return (L.sort $ albumShares album) + case newShares /= oldShares of + True -> do + rcptIds <- return $ L.nub $ newShares L.\\ oldShares + rcptMails <- mapM (\uId -> do + user <- runDB $ getJust uId + return $ userEmail user + ) rcptIds + mapM (\addr -> sendMail addr "A new album was shared with you" $ + [shamlet| +

Hi there! + #{ownerName} was so kind to share his album #{albumTitle album} with you. + |] + ) rcptMails + False -> do + return [()] + -- nothing to do here aId <- runDB $ update albumId [ AlbumTitle =. albumTitle temp - , AlbumShares =. albumShares temp + , AlbumShares =. newShares , AlbumSamplePic =. albumSamplePic temp ] setMessage "Album settings changed succesfully"