{-# LANGUAGE TemplateHaskell #-}
module Matterhorn.Types.MessageInterface
( MessageInterface(..)
, miMessages
, miEditor
, miMode
, miMessageSelect
, miRootPostId
, miChannelId
, miTarget
, miUrlListSource
, miUrlList
, miSaveAttachmentDialog
, messageInterfaceCursor
, MessageInterfaceMode(..)
, MessageInterfaceTarget(..)
, URLListSource(..)
, URLList(..)
, ulList
, ulSource
, SaveAttachmentDialogState(..)
, attachmentPathEditor
, attachmentPathDialogFocus
)
where
import Prelude ()
import Matterhorn.Prelude
import Brick ( getName )
import Brick.Focus ( FocusRing )
import Brick.Widgets.List ( List )
import Brick.Widgets.Edit ( Editor )
import Brick.Widgets.FileBrowser ( fileBrowserNameG )
import qualified Data.Text as T
import Lens.Micro.Platform ( makeLenses, _Just )
import Network.Mattermost.Types ( ChannelId, TeamId )
import Matterhorn.Types.Core ( MessageSelectState )
import Matterhorn.Types.EditState
import Matterhorn.Types.Messages
data MessageInterface n i =
MessageInterface { forall n i. MessageInterface n i -> Messages
_miMessages :: Messages
, forall n i. MessageInterface n i -> EditState n
_miEditor :: EditState n
, forall n i. MessageInterface n i -> MessageSelectState
_miMessageSelect :: MessageSelectState
, forall n i. MessageInterface n i -> i
_miRootPostId :: i
, forall n i. MessageInterface n i -> ChannelId
_miChannelId :: ChannelId
, forall n i. MessageInterface n i -> MessageInterfaceMode
_miMode :: MessageInterfaceMode
, forall n i. MessageInterface n i -> MessageInterfaceTarget
_miTarget :: MessageInterfaceTarget
, forall n i. MessageInterface n i -> URLListSource
_miUrlListSource :: URLListSource
, forall n i. MessageInterface n i -> URLList n
_miUrlList :: URLList n
, forall n i. MessageInterface n i -> SaveAttachmentDialogState n
_miSaveAttachmentDialog :: SaveAttachmentDialogState n
}
messageInterfaceCursor :: MessageInterface n i -> Maybe n
messageInterfaceCursor :: forall n i. MessageInterface n i -> Maybe n
messageInterfaceCursor MessageInterface n i
mi =
case forall n i. MessageInterface n i -> MessageInterfaceMode
_miMode MessageInterface n i
mi of
MessageInterfaceMode
Compose -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a n. Named a n => a -> n
getName forall a b. (a -> b) -> a -> b
$ forall n. EditState n -> Editor Text n
_esEditor forall a b. (a -> b) -> a -> b
$ forall n i. MessageInterface n i -> EditState n
_miEditor MessageInterface n i
mi
SaveAttachment {} -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a n. Named a n => a -> n
getName forall a b. (a -> b) -> a -> b
$ forall n. SaveAttachmentDialogState n -> Editor Text n
_attachmentPathEditor forall a b. (a -> b) -> a -> b
$ forall n i. MessageInterface n i -> SaveAttachmentDialogState n
_miSaveAttachmentDialog MessageInterface n i
mi
MessageInterfaceMode
BrowseFiles -> (forall n. EditState n -> Maybe (FileBrowser n)
_esFileBrowser forall a b. (a -> b) -> a -> b
$ forall n i. MessageInterface n i -> EditState n
_miEditor MessageInterface n i
mi)forall s a. s -> Getting (First a) s a -> Maybe a
^?forall a a'. Traversal (Maybe a) (Maybe a') a a'
_Justforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall n. SimpleGetter (FileBrowser n) n
fileBrowserNameG
MessageInterfaceMode
ManageAttachments -> forall a. Maybe a
Nothing
MessageInterfaceMode
MessageSelect -> forall a. Maybe a
Nothing
MessageInterfaceMode
ShowUrlList -> forall a. Maybe a
Nothing
data MessageInterfaceMode =
Compose
| MessageSelect
| ShowUrlList
| SaveAttachment LinkChoice
| ManageAttachments
| BrowseFiles
deriving (MessageInterfaceMode -> MessageInterfaceMode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MessageInterfaceMode -> MessageInterfaceMode -> Bool
$c/= :: MessageInterfaceMode -> MessageInterfaceMode -> Bool
== :: MessageInterfaceMode -> MessageInterfaceMode -> Bool
$c== :: MessageInterfaceMode -> MessageInterfaceMode -> Bool
Eq, Int -> MessageInterfaceMode -> ShowS
[MessageInterfaceMode] -> ShowS
MessageInterfaceMode -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MessageInterfaceMode] -> ShowS
$cshowList :: [MessageInterfaceMode] -> ShowS
show :: MessageInterfaceMode -> String
$cshow :: MessageInterfaceMode -> String
showsPrec :: Int -> MessageInterfaceMode -> ShowS
$cshowsPrec :: Int -> MessageInterfaceMode -> ShowS
Show)
data URLListSource =
FromChannel ChannelId
| FromThreadIn ChannelId
deriving (Int -> URLListSource -> ShowS
[URLListSource] -> ShowS
URLListSource -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [URLListSource] -> ShowS
$cshowList :: [URLListSource] -> ShowS
show :: URLListSource -> String
$cshow :: URLListSource -> String
showsPrec :: Int -> URLListSource -> ShowS
$cshowsPrec :: Int -> URLListSource -> ShowS
Show, URLListSource -> URLListSource -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: URLListSource -> URLListSource -> Bool
$c/= :: URLListSource -> URLListSource -> Bool
== :: URLListSource -> URLListSource -> Bool
$c== :: URLListSource -> URLListSource -> Bool
Eq)
data MessageInterfaceTarget =
MITeamThread TeamId
| MIChannel ChannelId
deriving (MessageInterfaceTarget -> MessageInterfaceTarget -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MessageInterfaceTarget -> MessageInterfaceTarget -> Bool
$c/= :: MessageInterfaceTarget -> MessageInterfaceTarget -> Bool
== :: MessageInterfaceTarget -> MessageInterfaceTarget -> Bool
$c== :: MessageInterfaceTarget -> MessageInterfaceTarget -> Bool
Eq, Int -> MessageInterfaceTarget -> ShowS
[MessageInterfaceTarget] -> ShowS
MessageInterfaceTarget -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MessageInterfaceTarget] -> ShowS
$cshowList :: [MessageInterfaceTarget] -> ShowS
show :: MessageInterfaceTarget -> String
$cshow :: MessageInterfaceTarget -> String
showsPrec :: Int -> MessageInterfaceTarget -> ShowS
$cshowsPrec :: Int -> MessageInterfaceTarget -> ShowS
Show)
data URLList n =
URLList { forall n. URLList n -> List n (Int, LinkChoice)
_ulList :: List n (Int, LinkChoice)
, forall n. URLList n -> Maybe URLListSource
_ulSource :: Maybe URLListSource
}
data SaveAttachmentDialogState n =
SaveAttachmentDialogState { forall n. SaveAttachmentDialogState n -> Editor Text n
_attachmentPathEditor :: Editor T.Text n
, forall n. SaveAttachmentDialogState n -> FocusRing n
_attachmentPathDialogFocus :: FocusRing n
}
makeLenses ''MessageInterface
makeLenses ''URLList
makeLenses ''SaveAttachmentDialogState