2015-01-18 19:44:41 +00:00
|
|
|
-- 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
|
2015-01-21 09:00:18 +00:00
|
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-01-18 19:44:41 +00:00
|
|
|
|
2014-08-12 21:45:33 +00:00
|
|
|
module Handler.Profile where
|
|
|
|
|
|
|
|
import Import
|
2014-08-15 11:25:33 +00:00
|
|
|
import Data.Maybe
|
2014-08-28 16:08:56 +00:00
|
|
|
import qualified Data.Text as T
|
2015-02-12 04:25:15 +00:00
|
|
|
import System.FilePath
|
2015-09-26 09:15:20 +00:00
|
|
|
import Yesod.RssFeed
|
|
|
|
import Yesod.AtomFeed
|
2014-08-12 21:45:33 +00:00
|
|
|
|
2014-08-14 00:26:21 +00:00
|
|
|
getProfileR :: UserId -> Handler Html
|
2014-08-18 01:10:33 +00:00
|
|
|
getProfileR ownerId = do
|
2014-09-24 21:03:18 +00:00
|
|
|
tempOwner <- runDB $ get ownerId
|
|
|
|
case tempOwner of
|
|
|
|
Just owner -> do
|
2015-09-14 16:54:46 +00:00
|
|
|
let ownerSlug = userSlug owner
|
2014-09-24 21:03:18 +00:00
|
|
|
userAlbs <- runDB $ selectList [AlbumOwner ==. ownerId] [Asc AlbumTitle]
|
2014-12-06 03:39:24 +00:00
|
|
|
allAlbs <- runDB $ selectList [] [Asc AlbumTitle]
|
2015-09-14 16:54:46 +00:00
|
|
|
almostAlbs <- mapM (\alb ->
|
|
|
|
if
|
|
|
|
ownerId `elem` albumShares (entityVal alb)
|
|
|
|
then return $ Just alb
|
|
|
|
else return Nothing
|
2014-12-06 03:39:24 +00:00
|
|
|
) allAlbs
|
2017-04-26 19:43:22 +00:00
|
|
|
let sharedAlbs = catMaybes almostAlbs
|
2015-09-14 16:54:46 +00:00
|
|
|
recentMedia <- runDB $ selectList [MediumOwner ==. ownerId] [Desc MediumTime]
|
2017-04-26 19:43:22 +00:00
|
|
|
-- msu <- lookupSession "userId"
|
|
|
|
musername <- maybeAuthId
|
|
|
|
presence <- case musername of
|
|
|
|
Just username ->
|
|
|
|
return (username == userName owner)
|
2014-09-24 21:03:18 +00:00
|
|
|
Nothing ->
|
|
|
|
return False
|
|
|
|
defaultLayout $ do
|
2017-04-26 19:43:22 +00:00
|
|
|
setTitle $ toHtml ("Eidolon :: " `T.append` ownerSlug `T.append` "'s profile")
|
|
|
|
rssLink (UserFeedRssR ownerId) (ownerSlug `T.append` "'s feed")
|
|
|
|
atomLink (UserFeedAtomR ownerId) (ownerSlug `T.append` "'s feed")
|
2014-09-24 21:03:18 +00:00
|
|
|
$(widgetFile "profile")
|
|
|
|
Nothing -> do
|
|
|
|
setMessage "This profile does not exist"
|
2015-09-14 16:54:46 +00:00
|
|
|
redirect HomeR
|
2014-08-18 16:08:53 +00:00
|
|
|
|
|
|
|
getUserR :: Text -> Handler Html
|
|
|
|
getUserR ownerName = do
|
2015-08-18 21:58:33 +00:00
|
|
|
tempOwner <- runDB $ getBy $ UniqueUser ownerName
|
2014-08-18 16:08:53 +00:00
|
|
|
case tempOwner of
|
2014-12-28 06:12:25 +00:00
|
|
|
Just (Entity ownerId _) ->
|
2014-08-18 16:08:53 +00:00
|
|
|
getProfileR ownerId
|
|
|
|
Nothing -> do
|
|
|
|
setMessage "This user does not exist"
|
2015-09-14 16:54:46 +00:00
|
|
|
redirect HomeR
|