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
|
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
|
|
|
|
ownerSlug <- lift $ pure $ userSlug owner
|
|
|
|
userAlbs <- runDB $ selectList [AlbumOwner ==. ownerId] [Asc AlbumTitle]
|
2014-12-06 03:39:24 +00:00
|
|
|
allAlbs <- runDB $ selectList [] [Asc AlbumTitle]
|
|
|
|
almostAlbs <- mapM (\alb -> do
|
|
|
|
case ownerId `elem` (albumShares $ entityVal alb) of
|
|
|
|
True -> return $ Just alb
|
|
|
|
False -> return Nothing
|
|
|
|
) allAlbs
|
|
|
|
sharedAlbs <- return $ removeItem Nothing almostAlbs
|
2014-09-24 21:03:18 +00:00
|
|
|
recentMedia <- (runDB $ selectList [MediumOwner ==. ownerId] [Desc MediumTime])
|
|
|
|
msu <- lookupSession "userId"
|
|
|
|
presence <- case msu of
|
|
|
|
Just tempUserId -> do
|
|
|
|
userId <- lift $ pure $ getUserIdFromText tempUserId
|
|
|
|
return (userId == ownerId)
|
|
|
|
Nothing ->
|
|
|
|
return False
|
|
|
|
defaultLayout $ do
|
|
|
|
setTitle $ toHtml ("Eidolon :: " `T.append` (userSlug owner) `T.append` "'s profile")
|
|
|
|
$(widgetFile "profile")
|
|
|
|
Nothing -> do
|
|
|
|
setMessage "This profile does not exist"
|
|
|
|
redirect $ HomeR
|
2014-08-18 16:08:53 +00:00
|
|
|
|
|
|
|
getUserR :: Text -> Handler Html
|
|
|
|
getUserR ownerName = do
|
|
|
|
tempOwner <- runDB $ selectFirst [UserName ==. ownerName] []
|
|
|
|
case tempOwner of
|
|
|
|
Just (Entity ownerId owner) ->
|
|
|
|
getProfileR ownerId
|
|
|
|
Nothing -> do
|
|
|
|
setMessage "This user does not exist"
|
|
|
|
redirect $ HomeR
|