{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Matterhorn.Draw.UserListWindow
( drawUserListWindow
)
where
import Prelude ()
import Matterhorn.Prelude
import Brick
import qualified Brick.Widgets.List as L
import qualified Data.Text as T
import qualified Graphics.Vty as V
import Network.Mattermost.Types ( TeamId )
import Matterhorn.Draw.Util ( userSigilFromInfo )
import Matterhorn.Draw.ListWindow ( drawListWindow, WindowPosition(..) )
import Matterhorn.Themes
import Matterhorn.Types
drawUserListWindow :: ChatState -> TeamId -> Widget Name
drawUserListWindow :: ChatState -> TeamId -> Widget Name
drawUserListWindow ChatState
st TeamId
tId =
let window :: Widget Name
window = forall a b.
ListWindowState a b
-> (b -> Widget Name)
-> (b -> Widget Name)
-> (b -> Widget Name)
-> (Bool -> a -> Widget Name)
-> Maybe (Widget Name)
-> WindowPosition
-> Int
-> Widget Name
drawListWindow (ChatState
stforall s a. s -> Getting a s a -> a
^.TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)forall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' TeamState (ListWindowState UserInfo UserSearchScope)
tsUserListWindow) UserSearchScope -> Widget Name
userSearchScopeHeader
UserSearchScope -> Widget Name
userSearchScopeNoResults UserSearchScope -> Widget Name
userSearchScopePrompt
(Text -> Bool -> UserInfo -> Widget Name
renderUser (ChatState -> Text
myUsername ChatState
st))
forall a. Maybe a
Nothing
WindowPosition
WindowCenter
Int
80
in forall n. Widget n -> Widget n
joinBorders Widget Name
window
userSearchScopePrompt :: UserSearchScope -> Widget Name
userSearchScopePrompt :: UserSearchScope -> Widget Name
userSearchScopePrompt UserSearchScope
scope =
forall n. Text -> Widget n
txt forall a b. (a -> b) -> a -> b
$ case UserSearchScope
scope of
ChannelMembers ChannelId
_ TeamId
_ -> Text
"Search channel members:"
ChannelNonMembers ChannelId
_ TeamId
_ -> Text
"Search users:"
AllUsers Maybe TeamId
Nothing -> Text
"Search users:"
AllUsers (Just TeamId
_) -> Text
"Search team members:"
userSearchScopeNoResults :: UserSearchScope -> Widget Name
userSearchScopeNoResults :: UserSearchScope -> Widget Name
userSearchScopeNoResults UserSearchScope
scope =
forall n. Text -> Widget n
txt forall a b. (a -> b) -> a -> b
$ case UserSearchScope
scope of
ChannelMembers ChannelId
_ TeamId
_ -> Text
"No users in channel."
ChannelNonMembers ChannelId
_ TeamId
_ -> Text
"All users in your team are already in this channel."
AllUsers Maybe TeamId
_ -> Text
"No users found."
userSearchScopeHeader :: UserSearchScope -> Widget Name
UserSearchScope
scope =
forall n. Text -> Widget n
txt forall a b. (a -> b) -> a -> b
$ case UserSearchScope
scope of
ChannelMembers {} -> Text
"Channel Members"
ChannelNonMembers {} -> Text
"Invite Users to Channel"
AllUsers Maybe TeamId
Nothing -> Text
"Users On This Server"
AllUsers (Just TeamId
_) -> Text
"Users In My Team"
renderUser :: Text -> Bool -> UserInfo -> Widget Name
renderUser :: Text -> Bool -> UserInfo -> Widget Name
renderUser Text
myUName Bool
foc UserInfo
ui =
(if Bool
foc then forall n. AttrName -> Widget n -> Widget n
forceAttr AttrName
L.listSelectedFocusedAttr else forall a. a -> a
id) forall a b. (a -> b) -> a -> b
$
forall n. Int -> Widget n -> Widget n
vLimit Int
2 forall a b. (a -> b) -> a -> b
$
forall n. Padding -> Widget n -> Widget n
padRight Padding
Max forall a b. (a -> b) -> a -> b
$
forall n. [Widget n] -> Widget n
hBox forall a b. (a -> b) -> a -> b
$ (forall n. Padding -> Widget n -> Widget n
padRight (Int -> Padding
Pad Int
1) forall a b. (a -> b) -> a -> b
$ forall a. Text -> Text -> Text -> Widget a
colorUsername Text
myUName (UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiName) (Char -> Text
T.singleton forall a b. (a -> b) -> a -> b
$ UserInfo -> Char
userSigilFromInfo UserInfo
ui))
forall a. a -> [a] -> [a]
: (forall n. Int -> Widget n -> Widget n
hLimit Int
usernameWidth forall a b. (a -> b) -> a -> b
$ forall n. Padding -> Widget n -> Widget n
padRight Padding
Max forall a b. (a -> b) -> a -> b
$ forall a. Text -> Text -> Text -> Widget a
colorUsername Text
myUName (UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiName) (UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiName))
forall a. a -> [a] -> [a]
: forall {n}. [Widget n]
extras
where
sanitize :: Text -> Text
sanitize = Text -> Text
T.strip forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> Text -> Text
T.replace Text
"\t" Text
" "
usernameWidth :: Int
usernameWidth = Int
20
extras :: [Widget n]
extras = forall n. Padding -> Widget n -> Widget n
padRight (Int -> Padding
Pad Int
1) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. [Maybe a] -> [a]
catMaybes [forall {n}. Maybe (Widget n)
mFullname, forall {n}. Maybe (Widget n)
mNickname, forall {n}. Maybe (Widget n)
mEmail]
mFullname :: Maybe (Widget n)
mFullname = if (Bool -> Bool
not (Text -> Bool
T.null (UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiFirstName)) Bool -> Bool -> Bool
|| Bool -> Bool
not (Text -> Bool
T.null (UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiLastName)))
then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall n. Text -> Widget n
txt forall a b. (a -> b) -> a -> b
$ (Text -> Text
sanitize forall a b. (a -> b) -> a -> b
$ UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiFirstName) forall a. Semigroup a => a -> a -> a
<> Text
" " forall a. Semigroup a => a -> a -> a
<> (Text -> Text
sanitize forall a b. (a -> b) -> a -> b
$ UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiLastName)
else forall a. Maybe a
Nothing
mNickname :: Maybe (Widget n)
mNickname = case UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo (Maybe Text)
uiNickName of
Just Text
n | Text
n forall a. Eq a => a -> a -> Bool
/= (UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiName) -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall n. Text -> Widget n
txt forall a b. (a -> b) -> a -> b
$ Text
"(" forall a. Semigroup a => a -> a -> a
<> Text
n forall a. Semigroup a => a -> a -> a
<> Text
")"
Maybe Text
_ -> forall a. Maybe a
Nothing
mEmail :: Maybe (Widget n)
mEmail = if (Text -> Bool
T.null forall a b. (a -> b) -> a -> b
$ UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiEmail)
then forall a. Maybe a
Nothing
else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall n. (Attr -> Attr) -> Widget n -> Widget n
modifyDefAttr (Attr -> Text -> Attr
`V.withURL` (Text
"mailto:" forall a. Semigroup a => a -> a -> a
<> UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiEmail)) forall a b. (a -> b) -> a -> b
$
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
urlAttr (forall n. Text -> Widget n
txt (Text
"<" forall a. Semigroup a => a -> a -> a
<> UserInfo
uiforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiEmail forall a. Semigroup a => a -> a -> a
<> Text
">"))