module Matterhorn.Events.Mouse
( mouseHandlerByMode
)
where
import Prelude ()
import Matterhorn.Prelude
import Brick
import Network.Mattermost.Types ( TeamId )
import Matterhorn.State.Channels
import Matterhorn.State.Teams ( setTeam )
import Matterhorn.State.ListWindow ( listWindowActivate )
import Matterhorn.Types
import Matterhorn.Events.EditNotifyPrefs ( handleEditNotifyPrefsEvent )
import Matterhorn.Events.ChannelTopicWindow ( channelTopicWindowMouseHandler )
import Matterhorn.State.MessageSelect ( exitMessageSelect )
import Matterhorn.State.Reactions ( toggleReaction )
import Matterhorn.State.Links ( openLinkTarget )
mouseHandlerByMode :: TeamId -> Mode -> BrickEvent Name MHEvent -> MH ()
mouseHandlerByMode :: TeamId -> Mode -> BrickEvent Name MHEvent -> MH ()
mouseHandlerByMode TeamId
tId Mode
mode =
case Mode
mode of
Mode
ChannelSelect -> TeamId -> BrickEvent Name MHEvent -> MH ()
channelSelectMouseHandler TeamId
tId
Mode
EditNotifyPrefs -> MH Bool -> MH ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MH Bool -> MH ())
-> (BrickEvent Name MHEvent -> MH Bool)
-> BrickEvent Name MHEvent
-> MH ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TeamId -> BrickEvent Name MHEvent -> MH Bool
handleEditNotifyPrefsEvent TeamId
tId
Mode
ReactionEmojiListWindow -> TeamId -> BrickEvent Name MHEvent -> MH ()
reactionEmojiListMouseHandler TeamId
tId
Mode
ChannelTopicWindow -> TeamId -> BrickEvent Name MHEvent -> MH ()
channelTopicWindowMouseHandler TeamId
tId
Mode
_ -> TeamId -> BrickEvent Name MHEvent -> MH ()
globalMouseHandler TeamId
tId
globalMouseHandler :: TeamId -> BrickEvent Name MHEvent -> MH ()
globalMouseHandler :: TeamId -> BrickEvent Name MHEvent -> MH ()
globalMouseHandler TeamId
tId (MouseDown Name
n Button
_ [Modifier]
_ Location
_) = do
ChatState
st <- Getting ChatState ChatState ChatState -> MH ChatState
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting ChatState ChatState ChatState
forall a. a -> a
id
case Name
n of
ClickableChannelListEntry ChannelId
channelId -> do
TeamId -> Mode -> MH () -> MH ()
whenMode TeamId
tId Mode
Main (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$ do
TeamId -> MH ()
resetReturnChannel TeamId
tId
TeamId -> ChannelId -> MH ()
setFocus TeamId
tId ChannelId
channelId
ClickableTeamListEntry TeamId
teamId ->
TeamId -> MH ()
setTeam TeamId
teamId
ClickableURL Maybe MessageId
_ Name
_ Int
_ LinkTarget
t ->
MH () -> MH ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$ LinkTarget -> MH ()
openLinkTarget LinkTarget
t
ClickableUsername Maybe MessageId
_ Name
_ Int
_ Text
username | Text
username Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= ChatState -> Text
myUsername ChatState
st -> do
TeamId -> Mode -> MH () -> MH ()
whenMode TeamId
tId Mode
ViewMessage (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$ do
TeamId -> MH ()
popMode TeamId
tId
MessageInterfaceFocus
foc <- Getting MessageInterfaceFocus ChatState MessageInterfaceFocus
-> MH MessageInterfaceFocus
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Const MessageInterfaceFocus TeamState)
-> ChatState -> Const MessageInterfaceFocus ChatState)
-> ((MessageInterfaceFocus
-> Const MessageInterfaceFocus MessageInterfaceFocus)
-> TeamState -> Const MessageInterfaceFocus TeamState)
-> Getting MessageInterfaceFocus ChatState MessageInterfaceFocus
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(MessageInterfaceFocus
-> Const MessageInterfaceFocus MessageInterfaceFocus)
-> TeamState -> Const MessageInterfaceFocus TeamState
Lens' TeamState MessageInterfaceFocus
tsMessageInterfaceFocus)
case MessageInterfaceFocus
foc of
MessageInterfaceFocus
FocusThread ->
Lens' ChatState (MessageInterface Name PostId) -> MH ()
forall n i. Lens' ChatState (MessageInterface n i) -> MH ()
exitMessageSelect (Lens' ChatState (MessageInterface Name PostId) -> MH ())
-> Lens' ChatState (MessageInterface Name PostId) -> MH ()
forall a b. (a -> b) -> a -> b
$ HasCallStack =>
TeamId -> Lens' ChatState (MessageInterface Name PostId)
TeamId -> Lens' ChatState (MessageInterface Name PostId)
unsafeThreadInterface TeamId
tId
MessageInterfaceFocus
FocusCurrentChannel -> do
Maybe ChannelId
mcId <- Getting (Maybe ChannelId) ChatState (Maybe ChannelId)
-> MH (Maybe ChannelId)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> SimpleGetter ChatState (Maybe ChannelId)
csCurrentChannelId(TeamId
tId))
case Maybe ChannelId
mcId of
Maybe ChannelId
Nothing -> () -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just ChannelId
cId -> Lens' ChatState (MessageInterface Name ()) -> MH ()
forall n i. Lens' ChatState (MessageInterface n i) -> MH ()
exitMessageSelect (Lens' ChatState (MessageInterface Name ()) -> MH ())
-> Lens' ChatState (MessageInterface Name ()) -> MH ()
forall a b. (a -> b) -> a -> b
$ ChannelId -> Lens' ChatState (MessageInterface Name ())
csChannelMessageInterface ChannelId
cId
TeamId -> Text -> MH ()
changeChannelByName TeamId
tId (Text -> MH ()) -> Text -> MH ()
forall a b. (a -> b) -> a -> b
$ Text -> Text
addUserSigil Text
username
ClickableAttachmentInMessage Name
_ FileId
fId ->
MH () -> MH ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$ LinkTarget -> MH ()
openLinkTarget (LinkTarget -> MH ()) -> LinkTarget -> MH ()
forall a b. (a -> b) -> a -> b
$ FileId -> LinkTarget
LinkFileId FileId
fId
ClickableReaction PostId
pId Name
_ Text
t Set UserId
uIds ->
MH () -> MH ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$ PostId -> Text -> Set UserId -> MH ()
toggleReaction PostId
pId Text
t Set UserId
uIds
ClickableChannelListGroupHeading ChannelListGroupLabel
label ->
ChannelListGroupLabel -> MH ()
toggleChannelListGroupVisibility ChannelListGroupLabel
label
ClickableURLListEntry Int
_ LinkTarget
t ->
MH () -> MH ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$ LinkTarget -> MH ()
openLinkTarget LinkTarget
t
VScrollBar ClickableScrollbarElement
e Name
vpName -> do
let vp :: ViewportScroll Name
vp = Name -> ViewportScroll Name
forall n. n -> ViewportScroll n
viewportScroll Name
vpName
EventM Name ChatState () -> MH ()
forall a. EventM Name ChatState a -> MH a
mh (EventM Name ChatState () -> MH ())
-> EventM Name ChatState () -> MH ()
forall a b. (a -> b) -> a -> b
$ case ClickableScrollbarElement
e of
ClickableScrollbarElement
SBHandleBefore -> ViewportScroll Name -> forall s. Int -> EventM Name s ()
forall n. ViewportScroll n -> forall s. Int -> EventM n s ()
vScrollBy ViewportScroll Name
vp (-Int
1)
ClickableScrollbarElement
SBHandleAfter -> ViewportScroll Name -> forall s. Int -> EventM Name s ()
forall n. ViewportScroll n -> forall s. Int -> EventM n s ()
vScrollBy ViewportScroll Name
vp Int
1
ClickableScrollbarElement
SBTroughBefore -> ViewportScroll Name -> forall s. Direction -> EventM Name s ()
forall n. ViewportScroll n -> forall s. Direction -> EventM n s ()
vScrollPage ViewportScroll Name
vp Direction
Up
ClickableScrollbarElement
SBTroughAfter -> ViewportScroll Name -> forall s. Direction -> EventM Name s ()
forall n. ViewportScroll n -> forall s. Direction -> EventM n s ()
vScrollPage ViewportScroll Name
vp Direction
Down
ClickableScrollbarElement
SBBar -> () -> EventM Name ChatState ()
forall a. a -> EventM Name ChatState a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Name
_ ->
() -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
globalMouseHandler TeamId
_ BrickEvent Name MHEvent
_ =
() -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
channelSelectMouseHandler :: TeamId -> BrickEvent Name MHEvent -> MH ()
channelSelectMouseHandler :: TeamId -> BrickEvent Name MHEvent -> MH ()
channelSelectMouseHandler TeamId
tId (MouseDown (ClickableChannelSelectEntry ChannelSelectMatch
match) Button
_ [Modifier]
_ Location
_) = do
TeamId -> MH ()
popMode TeamId
tId
TeamId -> ChannelId -> MH ()
setFocus TeamId
tId (ChannelId -> MH ()) -> ChannelId -> MH ()
forall a b. (a -> b) -> a -> b
$ ChannelListEntry -> ChannelId
channelListEntryChannelId (ChannelListEntry -> ChannelId) -> ChannelListEntry -> ChannelId
forall a b. (a -> b) -> a -> b
$ ChannelSelectMatch -> ChannelListEntry
matchEntry ChannelSelectMatch
match
channelSelectMouseHandler TeamId
_ BrickEvent Name MHEvent
_ =
() -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
reactionEmojiListMouseHandler :: TeamId -> BrickEvent Name MHEvent -> MH ()
reactionEmojiListMouseHandler :: TeamId -> BrickEvent Name MHEvent -> MH ()
reactionEmojiListMouseHandler TeamId
tId (MouseDown (ClickableReactionEmojiListWindowEntry (Bool, Text)
val) Button
_ [Modifier]
_ Location
_) =
TeamId
-> Lens' ChatState (ListWindowState (Bool, Text) ())
-> (Bool, Text)
-> MH ()
forall a b.
TeamId -> Lens' ChatState (ListWindowState a b) -> a -> MH ()
listWindowActivate TeamId
tId (TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> f TeamState) -> ChatState -> f ChatState)
-> ((ListWindowState (Bool, Text) ()
-> f (ListWindowState (Bool, Text) ()))
-> TeamState -> f TeamState)
-> (ListWindowState (Bool, Text) ()
-> f (ListWindowState (Bool, Text) ()))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ListWindowState (Bool, Text) ()
-> f (ListWindowState (Bool, Text) ()))
-> TeamState -> f TeamState
Lens' TeamState (ListWindowState (Bool, Text) ())
tsReactionEmojiListWindow) (Bool, Text)
val
reactionEmojiListMouseHandler TeamId
_ BrickEvent Name MHEvent
_ =
() -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()