{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE RankNTypes #-}
module Matterhorn.Draw.Main
  ( drawMain
  )
where

import           Prelude ()
import           Matterhorn.Prelude

import           Brick
import           Brick.Widgets.Border
import           Data.List ( intersperse )
import           Data.Maybe ( fromJust )
import qualified Data.Text as T
import           Lens.Micro.Platform ( Lens' )

import           Network.Mattermost.Types ( Type(Direct, Private, Group)
                                          , TeamId, teamDisplayName, teamId
                                          )


import           Matterhorn.Draw.ChannelList ( renderChannelList )
import           Matterhorn.Draw.Messages
import           Matterhorn.Draw.MessageInterface
import           Matterhorn.Draw.Autocomplete
import           Matterhorn.Draw.Util
import           Matterhorn.Draw.RichText
import           Matterhorn.Themes
import           Matterhorn.Types
import           Matterhorn.Types.Common ( sanitizeUserText )
import qualified Matterhorn.Zipper as Z


drawMain :: ChatState -> Mode -> [Widget Name]
drawMain :: ChatState -> Mode -> [Widget Name]
drawMain ChatState
st Mode
mode =
    (ChatState -> Widget Name
connectionLayer ChatState
st forall a. a -> [a] -> [a]
: ChatState -> [Widget Name]
drawAutocompleteLayers ChatState
st) forall a. Semigroup a => a -> a -> a
<>
    [forall n. Widget n -> Widget n
joinBorders forall a b. (a -> b) -> a -> b
$ ChatState -> Mode -> Maybe TeamId -> Widget Name
mainInterface ChatState
st Mode
mode (ChatState
stforall s a. s -> Getting a s a -> a
^.SimpleGetter ChatState (Maybe TeamId)
csCurrentTeamId)]

connectionLayer :: ChatState -> Widget Name
connectionLayer :: ChatState -> Widget Name
connectionLayer ChatState
st =
    case ChatState
stforall s a. s -> Getting a s a -> a
^.Lens' ChatState ConnectionStatus
csConnectionStatus of
        ConnectionStatus
Connected -> forall n. Widget n
emptyWidget
        ConnectionStatus
Disconnected ->
            forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ do
                Context Name
ctx <- forall n. RenderM n (Context n)
getContext
                let aw :: Int
aw = Context Name
ctxforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL
                    w :: Int
w = forall (t :: * -> *) a. Foldable t => t a -> Int
length String
msg forall a. Num a => a -> a -> a
+ Int
2
                    msg :: String
msg = String
"NOT CONNECTED"
                forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Location -> Widget n -> Widget n
translateBy ((Int, Int) -> Location
Location (forall a. Ord a => a -> a -> a
max Int
0 (Int
aw forall a. Num a => a -> a -> a
- Int
w), Int
0)) forall a b. (a -> b) -> a -> b
$
                         forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
errorMessageAttr forall a b. (a -> b) -> a -> b
$
                         forall n. Widget n -> Widget n
border forall a b. (a -> b) -> a -> b
$ forall n. String -> Widget n
str String
msg

mainInterface :: ChatState -> Mode -> Maybe TeamId -> Widget Name
mainInterface :: ChatState -> Mode -> Maybe TeamId -> Widget Name
mainInterface ChatState
st Mode
mode Maybe TeamId
mtId =
    forall n. [Widget n] -> Widget n
vBox [ ChatState -> Widget Name
teamList ChatState
st
         , Widget Name
body
         ]
    where
    config :: Config
config = ChatState
stforall s a. s -> Getting a s a -> a
^.Lens' ChatState ChatResources
csResourcesforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' ChatResources Config
crConfiguration

    showChannelList :: Bool
showChannelList =
        Config
configforall s a. s -> Getting a s a -> a
^.Lens' Config Bool
configShowChannelListL Bool -> Bool -> Bool
||
        case Maybe TeamId
mtId of
            Maybe TeamId
Nothing -> Bool
True
            Just {} -> Mode
mode forall a. Eq a => a -> a -> Bool
== Mode
ChannelSelect

    body :: Widget Name
body = if Bool
showChannelList
           then case ChatState
stforall s a. s -> Getting a s a -> a
^.Lens' ChatState ChannelListOrientation
csChannelListOrientation of
               ChannelListOrientation
ChannelListLeft ->
                   forall n. [Widget n] -> Widget n
hBox [Widget Name
channelList, forall n. Widget n
vBorder, Widget Name
mainDisplay]
               ChannelListOrientation
ChannelListRight ->
                   forall n. [Widget n] -> Widget n
hBox [Widget Name
mainDisplay, forall n. Widget n
vBorder, Widget Name
channelList]
           else Widget Name
mainDisplay

    mainDisplay :: Widget Name
mainDisplay = forall n. Widget n -> Widget n
maybeSubdue Widget Name
messageInterface

    channelList :: Widget Name
channelList = forall {n}. Mode -> Widget n -> Widget n
channelListMaybeVlimit Mode
mode forall a b. (a -> b) -> a -> b
$
                  forall n. Int -> Widget n -> Widget n
hLimit Int
channelListWidth forall a b. (a -> b) -> a -> b
$ case Maybe TeamId
mtId of
                      Maybe TeamId
Nothing -> forall n. Char -> Widget n
fill Char
' '
                      Just TeamId
tId -> ChatState -> TeamId -> Widget Name
renderChannelList ChatState
st TeamId
tId
    channelListWidth :: Int
channelListWidth = Config -> Int
configChannelListWidth forall a b. (a -> b) -> a -> b
$ ChatState
stforall s a. s -> Getting a s a -> a
^.Lens' ChatState ChatResources
csResourcesforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' ChatResources Config
crConfiguration
    channelListMaybeVlimit :: Mode -> Widget n -> Widget n
channelListMaybeVlimit Mode
ChannelSelect Widget n
w =
        forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$ do
            Context n
ctx <- forall n. RenderM n (Context n)
getContext
            forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit (Context n
ctxforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availHeightL forall a. Num a => a -> a -> a
- Int
1) Widget n
w
    channelListMaybeVlimit Mode
_ Widget n
w = Widget n
w

    noMessageInterface :: Widget n
noMessageInterface = forall n. Char -> Widget n
fill Char
' '

    messageInterface :: Widget Name
messageInterface = forall a. a -> Maybe a -> a
fromMaybe forall n. Widget n
noMessageInterface forall a b. (a -> b) -> a -> b
$ do
        TeamId
tId <- Maybe TeamId
mtId
        let hs :: HighlightSet
hs = ChatState -> TeamId -> HighlightSet
getHighlightSet ChatState
st TeamId
tId

            channelHeader :: ClientChannel -> Widget Name
channelHeader ClientChannel
chan =
                forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
channelHeaderAttr forall a b. (a -> b) -> a -> b
$
                forall n. Padding -> Widget n -> Widget n
padRight Padding
Max forall a b. (a -> b) -> a -> b
$
                ChatState -> TeamId -> HighlightSet -> ClientChannel -> Widget Name
renderChannelHeader ChatState
st TeamId
tId HighlightSet
hs ClientChannel
chan

            focused :: Bool
focused = 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 MessageInterfaceFocus
tsMessageInterfaceFocus forall a. Eq a => a -> a -> Bool
== MessageInterfaceFocus
FocusCurrentChannel Bool -> Bool -> Bool
&&
                      Bool
threadShowing
            threadShowing :: Bool
threadShowing = forall a. Maybe a -> Bool
isJust forall a b. (a -> b) -> a -> b
$ 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 (Maybe ThreadInterface)
tsThreadInterface
            channelMessageIface :: ChannelId -> Widget Name
channelMessageIface ChannelId
cId =
                forall i.
ChatState
-> HighlightSet
-> TeamId
-> Bool
-> Lens' ChatState (MessageInterface Name i)
-> Bool
-> Bool
-> Widget Name
drawMessageInterface ChatState
st HighlightSet
hs TeamId
tId Bool
True
                                     (ChannelId -> Lens' ChatState ChannelMessageInterface
csChannelMessageInterface(ChannelId
cId))
                                     Bool
True
                                     Bool
focused

            maybeThreadIface :: Maybe (Widget Name)
maybeThreadIface = do
                ThreadInterface
_ <- 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 (Maybe ThreadInterface)
tsThreadInterface
                forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ChatState -> TeamId -> Widget Name
drawThreadWindow ChatState
st TeamId
tId

        ChannelId
cId <- ChatState
stforall s a. s -> Getting a s a -> a
^.TeamId -> SimpleGetter ChatState (Maybe ChannelId)
csCurrentChannelId(TeamId
tId)
        ClientChannel
ch <- ChatState
stforall s a. s -> Getting (First a) s a -> Maybe a
^?ChannelId -> Traversal' ChatState ClientChannel
csChannel(ChannelId
cId)

        let channelUI :: Widget Name
channelUI = ClientChannel -> Widget Name
channelHeader ClientChannel
ch forall n. Widget n -> Widget n -> Widget n
<=> forall n. Widget n
hBorder forall n. Widget n -> Widget n -> Widget n
<=> ChannelId -> Widget Name
channelMessageIface ChannelId
cId

        forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a -> a
fromMaybe Widget Name
channelUI forall a b. (a -> b) -> a -> b
$ do
            Widget Name
tui <- Maybe (Widget Name)
maybeThreadIface
            forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case Config
configforall s a. s -> Getting a s a -> a
^.Lens' Config ThreadOrientation
configThreadOrientationL of
                ThreadOrientation
ThreadAbove -> Widget Name
tui forall n. Widget n -> Widget n -> Widget n
<=> forall n. Widget n
hBorder forall n. Widget n -> Widget n -> Widget n
<=> Widget Name
channelUI
                ThreadOrientation
ThreadBelow -> Widget Name
channelUI forall n. Widget n -> Widget n -> Widget n
<=> forall n. Widget n
hBorder forall n. Widget n -> Widget n -> Widget n
<=> Widget Name
tui
                ThreadOrientation
ThreadLeft  -> Widget Name
tui forall n. Widget n -> Widget n -> Widget n
<+> forall n. Widget n
vBorder forall n. Widget n -> Widget n -> Widget n
<+> Widget Name
channelUI
                ThreadOrientation
ThreadRight -> Widget Name
channelUI forall n. Widget n -> Widget n -> Widget n
<+> forall n. Widget n
vBorder forall n. Widget n -> Widget n -> Widget n
<+> Widget Name
tui

    maybeSubdue :: Widget n -> Widget n
maybeSubdue = if Mode
mode forall a. Eq a => a -> a -> Bool
== Mode
ChannelSelect
                  then forall n. AttrName -> Widget n -> Widget n
forceAttr forall a b. (a -> b) -> a -> b
$ String -> AttrName
attrName String
""
                  else forall a. a -> a
id

teamList :: ChatState -> Widget Name
teamList :: ChatState -> Widget Name
teamList ChatState
st =
    let curTid :: Maybe TeamId
curTid = ChatState
stforall s a. s -> Getting a s a -> a
^.SimpleGetter ChatState (Maybe TeamId)
csCurrentTeamId
        z :: Zipper () TeamId
z = ChatState
stforall s a. s -> Getting a s a -> a
^.Lens' ChatState (Zipper () TeamId)
csTeamZipper
        pos :: Int
pos = forall a. HasCallStack => Maybe a -> a
fromJust forall a b. (a -> b) -> a -> b
$ forall b a. Eq b => Zipper a b -> Maybe Int
Z.position Zipper () TeamId
z
        teams :: [TeamState]
teams = (\TeamId
tId -> ChatState
stforall s a. s -> Getting a s a -> a
^.TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall a b. (a -> b) -> a -> b
$ forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a b. Zipper a b -> [(a, [b])]
Z.toList Zipper () TeamId
z)
        numTeams :: Int
numTeams = forall (t :: * -> *) a. Foldable t => t a -> Int
length [TeamState]
teams
        entries :: [Widget Name]
entries = TeamState -> Widget Name
mkEntry forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [TeamState]
teams
        mkEntry :: TeamState -> Widget Name
mkEntry TeamState
ts =
            let tId :: TeamId
tId = Team -> TeamId
teamId forall a b. (a -> b) -> a -> b
$ TeamState -> Team
_tsTeam TeamState
ts
                unread :: Bool
unread = Int
uCount forall a. Ord a => a -> a -> Bool
> Int
0
                uCount :: Int
uCount = TeamId -> ChatState -> Int
teamUnreadCount TeamId
tId ChatState
st
                tName :: Name
tName  = TeamId -> Name
ClickableTeamListEntry TeamId
tId
            in (if forall a. a -> Maybe a
Just TeamId
tId forall a. Eq a => a -> a -> Bool
== Maybe TeamId
curTid
                   then forall n. Widget n -> Widget n
visible forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
currentTeamAttr
                   else if Bool
unread
                        then forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
unreadChannelAttr
                        else forall a. a -> a
id) forall a b. (a -> b) -> a -> b
$
               forall n. Ord n => n -> Widget n -> Widget n
clickable Name
tName forall a b. (a -> b) -> a -> b
$ forall n. Text -> Widget n
txt forall a b. (a -> b) -> a -> b
$
               (Text -> Text
T.strip forall a b. (a -> b) -> a -> b
$ UserText -> Text
sanitizeUserText forall a b. (a -> b) -> a -> b
$ Team -> UserText
teamDisplayName forall a b. (a -> b) -> a -> b
$ TeamState -> Team
_tsTeam TeamState
ts)
    in if Int
numTeams forall a. Eq a => a -> a -> Bool
== Int
1
       then forall n. Widget n
emptyWidget
       else forall n. [Widget n] -> Widget n
vBox [ forall n. [Widget n] -> Widget n
hBox [ forall n. Padding -> Widget n -> Widget n
padRight (Int -> Padding
Pad Int
1) forall a b. (a -> b) -> a -> b
$ forall n. Text -> Widget n
txt forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ String
"Teams (" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show (Int
pos forall a. Num a => a -> a -> a
+ Int
1) forall a. Semigroup a => a -> a -> a
<> String
"/" forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Int
numTeams forall a. Semigroup a => a -> a -> a
<> String
"):"
                        , forall n. Int -> Widget n -> Widget n
vLimit Int
1 forall a b. (a -> b) -> a -> b
$ forall n.
(Ord n, Show n) =>
n -> ViewportType -> Widget n -> Widget n
viewport Name
TeamList ViewportType
Horizontal forall a b. (a -> b) -> a -> b
$
                          forall n. [Widget n] -> Widget n
hBox forall a b. (a -> b) -> a -> b
$
                          forall a. a -> [a] -> [a]
intersperse (forall n. Text -> Widget n
txt Text
" ") [Widget Name]
entries
                        ]
                 , forall n. Widget n
hBorder
                 ]

renderChannelHeader :: ChatState -> TeamId -> HighlightSet -> ClientChannel -> Widget Name
renderChannelHeader :: ChatState -> TeamId -> HighlightSet -> ClientChannel -> Widget Name
renderChannelHeader ChatState
st TeamId
tId HighlightSet
hs ClientChannel
chan =
    let chnType :: Type
chnType = ClientChannel
chanforall s a. s -> Getting a s a -> a
^.Lens' ClientChannel ChannelInfo
ccInfoforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' ChannelInfo Type
cdType
        topicStr :: Text
topicStr = ClientChannel
chanforall s a. s -> Getting a s a -> a
^.Lens' ClientChannel ChannelInfo
ccInfoforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' ChannelInfo Text
cdHeader
        userHeader :: UserInfo -> Text
userHeader UserInfo
u = let s :: Text
s = Text -> [Text] -> Text
T.intercalate Text
" " forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Bool
T.null) [Text]
parts
                           parts :: [Text]
parts = [ Text
chanName
                                   , if (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Text -> Bool
T.null [Text]
names)
                                     then forall a. Monoid a => a
mempty
                                     else Text
"is"
                                   ] forall a. Semigroup a => a -> a -> a
<> [Text]
names forall a. Semigroup a => a -> a -> a
<> [
                                     if Text -> Bool
T.null (UserInfo
uforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiEmail)
                                     then forall a. Monoid a => a
mempty
                                     else Text
"(" forall a. Semigroup a => a -> a -> a
<> UserInfo
uforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiEmail forall a. Semigroup a => a -> a -> a
<> Text
")"
                                   ]
                           names :: [Text]
names = [ UserInfo
uforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiFirstName
                                   , Text
nick
                                   , UserInfo
uforall s a. s -> Getting a s a -> a
^.Lens' UserInfo Text
uiLastName
                                   ]
                           quote :: a -> a
quote a
n = a
"\"" forall a. Semigroup a => a -> a -> a
<> a
n forall a. Semigroup a => a -> a -> a
<> a
"\""
                           nick :: Text
nick = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Text
"" forall {a}. (Semigroup a, IsString a) => a -> a
quote forall a b. (a -> b) -> a -> b
$ UserInfo
uforall s a. s -> Getting a s a -> a
^.Lens' UserInfo (Maybe Text)
uiNickName
                       in Text
s
        firstTopicLine :: Text
firstTopicLine = case Text -> [Text]
T.lines Text
topicStr of
            [Text
h] -> Text
h
            (Text
h:Text
_:[Text]
_) -> Text
h
            [Text]
_ -> Text
""
        maybeTopic :: Text
maybeTopic = if Text -> Bool
T.null Text
topicStr
                     then Text
""
                     else Text
" - " forall a. Semigroup a => a -> a -> a
<> if ChatState
stforall s a. s -> Getting a s a -> a
^.Lens' ChatState ChatResources
csResourcesforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' ChatResources Config
crConfigurationforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' Config Bool
configShowExpandedChannelTopicsL
                                   then Text
topicStr
                                   else Text
firstTopicLine
        channelNameString :: Text
channelNameString = case Type
chnType of
            Type
Direct ->
                case ClientChannel
chanforall s a. s -> Getting a s a -> a
^.Lens' ClientChannel ChannelInfo
ccInfoforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' ChannelInfo (Maybe UserId)
cdDMUserId forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a b c. (a -> b -> c) -> b -> a -> c
flip UserId -> ChatState -> Maybe UserInfo
userById ChatState
st of
                    Maybe UserInfo
Nothing -> Text
chanName
                    Just UserInfo
u -> UserInfo -> Text
userHeader UserInfo
u
            Type
Private ->
                Text
channelNamePair forall a. Semigroup a => a -> a -> a
<> Text
" (Private)"
            Type
Group ->
                Text
channelNamePair forall a. Semigroup a => a -> a -> a
<> Text
" (Private group)"
            Type
_ ->
                Text
channelNamePair
        channelNamePair :: Text
channelNamePair = Text
chanName forall a. Semigroup a => a -> a -> a
<> Text
" - " forall a. Semigroup a => a -> a -> a
<> (ClientChannel
chanforall s a. s -> Getting a s a -> a
^.Lens' ClientChannel ChannelInfo
ccInfoforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' ChannelInfo Text
cdDisplayName)
        chanName :: Text
chanName = ChatState -> ChannelInfo -> Text
mkChannelName ChatState
st (ClientChannel
chanforall s a. s -> Getting a s a -> a
^.Lens' ClientChannel ChannelInfo
ccInfo)
        baseUrl :: TeamBaseURL
baseUrl = ChatState -> TeamId -> TeamBaseURL
serverBaseUrl ChatState
st TeamId
tId

    in forall a.
SemEq a =>
Maybe TeamBaseURL
-> Text
-> HighlightSet
-> Maybe (Int -> Inline -> Maybe a)
-> Text
-> Widget a
renderText' (forall a. a -> Maybe a
Just TeamBaseURL
baseUrl) (ChatState -> Text
myUsername ChatState
st)
         HighlightSet
hs (forall a. a -> Maybe a
Just (Maybe MessageId -> Name -> Int -> Inline -> Maybe Name
mkClickableInline forall a. Maybe a
Nothing (ChannelId -> Name
ChannelTopic forall a b. (a -> b) -> a -> b
$ ClientChannel
chanforall s a. s -> Getting a s a -> a
^.Lens' ClientChannel ChannelInfo
ccInfoforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' ChannelInfo ChannelId
cdChannelId)))
         (Text
channelNameString forall a. Semigroup a => a -> a -> a
<> Text
maybeTopic)

drawThreadWindow :: ChatState -> TeamId -> Widget Name
drawThreadWindow :: ChatState -> TeamId -> Widget Name
drawThreadWindow ChatState
st TeamId
tId = forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
threadAttr Widget Name
body
    where
        ti :: Lens' ChatState ThreadInterface
        ti :: Lens' ChatState ThreadInterface
ti = HasCallStack => TeamId -> Lens' ChatState ThreadInterface
unsafeThreadInterface(TeamId
tId)

        hs :: HighlightSet
hs = ChatState -> TeamId -> HighlightSet
getHighlightSet ChatState
st TeamId
tId
        cId :: ChannelId
cId = ChatState
stforall s a. s -> Getting a s a -> a
^.Lens' ChatState ThreadInterface
tiforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall n i. Lens' (MessageInterface n i) ChannelId
miChannelId

        titleText :: Text
titleText = case ChatState
stforall s a. s -> Getting (First a) s a -> Maybe a
^?ChannelId -> Traversal' ChatState ClientChannel
csChannel(ChannelId
cId) of
            Maybe ClientChannel
Nothing -> Text
"Thread"
            Just ClientChannel
chan ->
                let prefix :: Text
prefix = case ClientChannel
chanforall s a. s -> Getting a s a -> a
^.Lens' ClientChannel ChannelInfo
ccInfoforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' ChannelInfo Type
cdType of
                        Type
Group -> Text
"Thread with "
                        Type
Direct -> Text
"Thread with "
                        Type
_ -> Text
"Thread in "
                in Text
prefix forall a. Semigroup a => a -> a -> a
<> ChatState -> ChannelInfo -> Text
mkChannelName ChatState
st (ClientChannel
chanforall s a. s -> Getting a s a -> a
^.Lens' ClientChannel ChannelInfo
ccInfo)

        title :: Widget Name
title = forall a.
SemEq a =>
Maybe TeamBaseURL
-> Text
-> HighlightSet
-> Maybe (Int -> Inline -> Maybe a)
-> Text
-> Widget a
renderText' forall a. Maybe a
Nothing Text
"" HighlightSet
hs forall a. Maybe a
Nothing Text
titleText
        focused :: Bool
focused = 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 MessageInterfaceFocus
tsMessageInterfaceFocus forall a. Eq a => a -> a -> Bool
== MessageInterfaceFocus
FocusThread
        body :: Widget Name
body = Widget Name
title forall n. Widget n -> Widget n -> Widget n
<=> forall n. Widget n
hBorder forall n. Widget n -> Widget n -> Widget n
<=> Widget Name
messageUI
        messageUI :: Widget Name
messageUI = forall i.
ChatState
-> HighlightSet
-> TeamId
-> Bool
-> Lens' ChatState (MessageInterface Name i)
-> Bool
-> Bool
-> Widget Name
drawMessageInterface ChatState
st HighlightSet
hs TeamId
tId Bool
False Lens' ChatState ThreadInterface
ti Bool
False Bool
focused