{-# LANGUAGE RankNTypes #-} module Matterhorn.Events.MessageSelect ( messageSelectKeybindings , messageSelectKeyHandlers , onEventMessageSelect , onEventMessageSelectDeleteConfirm ) where import Prelude () import Matterhorn.Prelude import Brick.Keybindings import qualified Data.Text as T import qualified Graphics.Vty as Vty import Lens.Micro.Platform ( Lens', to ) import Network.Mattermost.Types ( TeamId ) import Matterhorn.State.MessageSelect import Matterhorn.State.ReactionEmojiListWindow import Matterhorn.Types messagesPerPageOperation :: Int messagesPerPageOperation :: Int messagesPerPageOperation = Int 10 onEventMessageSelect :: TeamId -> Lens' ChatState (MessageInterface n i) -> Vty.Event -> MH Bool onEventMessageSelect :: forall n i. TeamId -> Lens' ChatState (MessageInterface n i) -> Event -> MH Bool onEventMessageSelect TeamId tId Lens' ChatState (MessageInterface n i) which = (KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH) -> Event -> MH Bool mhHandleKeyboardEvent (forall n i. TeamId -> Lens' ChatState (MessageInterface n i) -> KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH messageSelectKeybindings TeamId tId Lens' ChatState (MessageInterface n i) which) onEventMessageSelectDeleteConfirm :: TeamId -> Lens' ChatState (MessageInterface Name i) -> Vty.Event -> MH () onEventMessageSelectDeleteConfirm :: forall i. TeamId -> Lens' ChatState (MessageInterface Name i) -> Event -> MH () onEventMessageSelectDeleteConfirm TeamId tId Lens' ChatState (MessageInterface Name i) which (Vty.EvKey (Vty.KChar Char 'y') []) = do forall n i. Lens' ChatState (MessageInterface n i) -> MH () deleteSelectedMessage Lens' ChatState (MessageInterface Name i) which TeamId -> MH () popMode TeamId tId onEventMessageSelectDeleteConfirm TeamId _ Lens' ChatState (MessageInterface Name i) _ (Vty.EvResize {}) = do forall (m :: * -> *) a. Monad m => a -> m a return () onEventMessageSelectDeleteConfirm TeamId tId Lens' ChatState (MessageInterface Name i) _ Event _ = do TeamId -> MH () popMode TeamId tId messageSelectKeybindings :: TeamId -> Lens' ChatState (MessageInterface n i) -> KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH messageSelectKeybindings :: forall n i. TeamId -> Lens' ChatState (MessageInterface n i) -> KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH messageSelectKeybindings TeamId tId Lens' ChatState (MessageInterface n i) which KeyConfig KeyEvent kc = forall k (m :: * -> *). Ord k => KeyConfig k -> [KeyEventHandler k m] -> KeyDispatcher k m unsafeKeyDispatcher KeyConfig KeyEvent kc (forall n i. TeamId -> Lens' ChatState (MessageInterface n i) -> [MHKeyEventHandler] messageSelectKeyHandlers TeamId tId Lens' ChatState (MessageInterface n i) which) messageSelectKeyHandlers :: TeamId -> Lens' ChatState (MessageInterface n i) -> [MHKeyEventHandler] messageSelectKeyHandlers :: forall n i. TeamId -> Lens' ChatState (MessageInterface n i) -> [MHKeyEventHandler] messageSelectKeyHandlers TeamId tId Lens' ChatState (MessageInterface n i) which = [ forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent CancelEvent Text "Cancel message selection" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () exitMessageSelect Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent SelectUpEvent Text "Select the previous message" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () messageSelectUp Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent SelectDownEvent Text "Select the next message" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () messageSelectDown Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent ScrollTopEvent Text "Scroll to top and select the oldest message" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () messageSelectFirst Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent ScrollBottomEvent Text "Scroll to bottom and select the latest message" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () messageSelectLast Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent PageUpEvent (String -> Text T.pack forall a b. (a -> b) -> a -> b $ String "Move the cursor up by " forall a. Semigroup a => a -> a -> a <> forall a. Show a => a -> String show Int messagesPerPageOperation forall a. Semigroup a => a -> a -> a <> String " messages") (forall n i. Lens' ChatState (MessageInterface n i) -> Int -> MH () messageSelectUpBy Lens' ChatState (MessageInterface n i) which Int messagesPerPageOperation) , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent PageDownEvent (String -> Text T.pack forall a b. (a -> b) -> a -> b $ String "Move the cursor down by " forall a. Semigroup a => a -> a -> a <> forall a. Show a => a -> String show Int messagesPerPageOperation forall a. Semigroup a => a -> a -> a <> String " messages") (forall n i. Lens' ChatState (MessageInterface n i) -> Int -> MH () messageSelectDownBy Lens' ChatState (MessageInterface n i) which Int messagesPerPageOperation) , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent OpenMessageURLEvent Text "Open all URLs in the selected message" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () openSelectedMessageURLs Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent ReplyMessageEvent Text "Begin composing a reply to the selected message" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () beginReplyCompose Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent EditMessageEvent Text "Begin editing the selected message" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () beginEditMessage Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent DeleteMessageEvent Text "Delete the selected message (with confirmation)" forall a b. (a -> b) -> a -> b $ forall n i. TeamId -> Lens' ChatState (MessageInterface n i) -> MH () beginConfirmDeleteSelectedMessage TeamId tId Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent YankMessageEvent Text "Copy a verbatim section or message to the clipboard" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () yankSelectedMessageVerbatim Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent YankWholeMessageEvent Text "Copy an entire message to the clipboard" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () yankSelectedMessage Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent PinMessageEvent Text "Toggle whether the selected message is pinned" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () pinSelectedMessage Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent FlagMessageEvent Text "Flag the selected message" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () flagSelectedMessage Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent ViewMessageEvent Text "View the selected message" forall a b. (a -> b) -> a -> b $ forall n i. TeamId -> Lens' ChatState (MessageInterface n i) -> MH () viewSelectedMessage TeamId tId Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent OpenThreadEvent Text "Open the selected message's thread in a thread window" forall a b. (a -> b) -> a -> b $ do forall n i. TeamId -> Lens' ChatState (MessageInterface n i) -> MH () openThreadWindow TeamId tId Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent FillGapEvent Text "Fetch messages for the selected gap" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () fillSelectedGap Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent ReactToMessageEvent Text "Post a reaction to the selected message" forall a b. (a -> b) -> a -> b $ do Maybe Message mMsg <- forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a use (forall s a. (s -> a) -> SimpleGetter s a to (forall n i. Lens' ChatState (MessageInterface n i) -> ChatState -> Maybe Message getSelectedMessage Lens' ChatState (MessageInterface n i) which)) case Maybe Message mMsg of Maybe Message Nothing -> forall (m :: * -> *) a. Monad m => a -> m a return () Just Message m -> TeamId -> Message -> MH () enterReactionEmojiListWindowMode TeamId tId Message m , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent CopyPostLinkEvent Text "Copy a post's link to the clipboard" forall a b. (a -> b) -> a -> b $ forall n i. TeamId -> Lens' ChatState (MessageInterface n i) -> MH () copyPostLink TeamId tId Lens' ChatState (MessageInterface n i) which , forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m onEvent KeyEvent OpenMessageInExternalEditorEvent Text "Open the message's source in $EDITOR" forall a b. (a -> b) -> a -> b $ forall n i. Lens' ChatState (MessageInterface n i) -> MH () openSelectedMessageInEditor Lens' ChatState (MessageInterface n i) which ]