44 lines
1.5 KiB
Haskell
44 lines
1.5 KiB
Haskell
module Handler.Profile where
|
|
|
|
import Import
|
|
import Data.Maybe
|
|
import qualified Data.Text as T
|
|
|
|
getProfileR :: UserId -> Handler Html
|
|
getProfileR ownerId = do
|
|
tempOwner <- runDB $ get ownerId
|
|
case tempOwner of
|
|
Just owner -> do
|
|
ownerSlug <- lift $ pure $ userSlug owner
|
|
userAlbs <- runDB $ selectList [AlbumOwner ==. ownerId] [Asc AlbumTitle]
|
|
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
|
|
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
|
|
|
|
getUserR :: Text -> Handler Html
|
|
getUserR ownerName = do
|
|
tempOwner <- runDB $ selectFirst [UserName ==. ownerName] []
|
|
case tempOwner of
|
|
Just (Entity ownerId _) ->
|
|
getProfileR ownerId
|
|
Nothing -> do
|
|
setMessage "This user does not exist"
|
|
redirect $ HomeR
|