summaryrefslogtreecommitdiffhomepage
path: root/ControlWindow.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-29 15:33:34 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-29 15:33:34 -0400
commitaf251f41daac5593bae8986112c672e7efc08290 (patch)
tree0958b91418169f8b7755e42a2c77ba380a2d3de0 /ControlWindow.hs
parent6a92c954c8018f7acf25cc8a0e66bce5d1eed781 (diff)
downloaddebug-me-af251f41daac5593bae8986112c672e7efc08290.tar.gz
fix server to not relay developer messages back to self
This fixes chat message echoing consistency too.
Diffstat (limited to 'ControlWindow.hs')
-rw-r--r--ControlWindow.hs32
1 files changed, 21 insertions, 11 deletions
diff --git a/ControlWindow.hs b/ControlWindow.hs
index 3bd0e58..74514be 100644
--- a/ControlWindow.hs
+++ b/ControlWindow.hs
@@ -84,13 +84,19 @@ collectOutput ochan promptchan responsechan = do
myusername <- fromString <$> getLoginName
withLines stdin $ mapM_ $ processline myusername
where
- processline myusername l = atomically $ do
- -- Is any particular input being prompted for now?
- mp <- tryReadTChan promptchan
- case mp of
- Just _ -> writeTChan responsechan $ L.toStrict l
- Nothing -> writeTMChan ochan $ ControlOutputAction $
- ChatMessage (Val myusername) (Val $ L.toStrict l)
+ processline myusername l = do
+ mc <- atomically $ do
+ -- Is any particular input being prompted for now?
+ mp <- tryReadTChan promptchan
+ case mp of
+ Just _ -> do
+ writeTChan responsechan $ L.toStrict l
+ return Nothing
+ Nothing -> do
+ let c = ChatMessage (Val myusername) (Val $ L.toStrict l)
+ writeTMChan ochan $ ControlOutputAction c
+ return (Just c)
+ maybe (return ()) displayChatMessage mc
displayInput :: TMChan ControlOutput -> TMChan ControlInput -> PromptChan -> ResponseChan -> IO ()
displayInput ochan ichan promptchan responsechan = loop
@@ -103,13 +109,17 @@ displayInput ochan ichan promptchan responsechan = loop
go (Just (ControlInputAction (SessionKey k))) = do
askToAllow ochan promptchan responsechan k
loop
- go (Just (ControlInputAction (ChatMessage username msg))) = do
- B.putStr $ "<" <> val username <> "> " <> val msg
- putStr "\n"
- hFlush stdout
+ go (Just (ControlInputAction m@(ChatMessage {}))) = do
+ displayChatMessage m
loop
go _ = loop
+displayChatMessage :: ControlAction -> IO ()
+displayChatMessage (ChatMessage username msg) = do
+ B.putStr $ "<" <> val username <> "> " <> val msg <> "\n"
+ hFlush stdout
+displayChatMessage _ = return ()
+
askToAllow :: TMChan ControlOutput -> PromptChan -> ResponseChan -> PerhapsSigned PublicKey -> IO ()
askToAllow ochan _ _ (UnSigned pk) = atomically $ writeTMChan ochan $
ControlOutputAction $ SessionKeyRejected pk