mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
core: simplify terminal mark messages read logic (#1589)
This commit is contained in:
@@ -35,7 +35,7 @@ runInputLoop ct cc = forever $ do
|
||||
s <- atomically . readTBQueue $ inputQ cc
|
||||
let bs = encodeUtf8 $ T.pack s
|
||||
cmd = parseChatCommand bs
|
||||
when (doEcho cmd) $ echo s
|
||||
unless (isMessage cmd) $ echo s
|
||||
r <- runReaderT (execChatCommand bs) cc
|
||||
case r of
|
||||
CRChatCmdError _ -> when (isMessage cmd) $ echo s
|
||||
@@ -46,9 +46,6 @@ runInputLoop ct cc = forever $ do
|
||||
printToTerminal ct $ responseToView user testV ts r
|
||||
where
|
||||
echo s = printToTerminal ct [plain s]
|
||||
doEcho cmd = case cmd of
|
||||
Right APIChatRead {} -> False
|
||||
_ -> not $ isMessage cmd
|
||||
isMessage = \case
|
||||
Right SendMessage {} -> True
|
||||
Right SendFile {} -> True
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
module Simplex.Chat.Terminal.Output where
|
||||
|
||||
import Control.Monad.Catch (MonadMask)
|
||||
import Control.Monad.IO.Unlift
|
||||
import Control.Monad.Except
|
||||
import Control.Monad.Reader
|
||||
import Data.Time.Clock (getCurrentTime)
|
||||
import Simplex.Chat (processChatCommand)
|
||||
import Simplex.Chat.Controller
|
||||
import Simplex.Chat.Messages hiding (NewChatItem (..))
|
||||
import Simplex.Chat.Styled
|
||||
@@ -75,7 +76,7 @@ withTermLock ChatTerminal {termLock} action = do
|
||||
atomically $ putTMVar termLock ()
|
||||
|
||||
runTerminalOutput :: ChatTerminal -> ChatController -> IO ()
|
||||
runTerminalOutput ct ChatController {currentUser, inputQ, outputQ, config = ChatConfig {testView}} = do
|
||||
runTerminalOutput ct cc@ChatController {currentUser, outputQ, config = ChatConfig {testView}} = do
|
||||
forever $ do
|
||||
(_, r) <- atomically $ readTBQueue outputQ
|
||||
case r of
|
||||
@@ -91,9 +92,8 @@ runTerminalOutput ct ChatController {currentUser, inputQ, outputQ, config = Chat
|
||||
case (muted chat item, itemStatus) of
|
||||
(False, CISRcvNew) -> do
|
||||
let itemId = chatItemId' item
|
||||
chatRef = serializeChatRef $ chatInfoToRef chat
|
||||
cmd = "/_read chat " <> chatRef <> " from=" <> show itemId <> " to=" <> show itemId
|
||||
atomically $ writeTBQueue inputQ cmd
|
||||
chatRef = chatInfoToRef chat
|
||||
void $ runReaderT (runExceptT $ processChatCommand (APIChatRead chatRef (Just (itemId, itemId)))) cc
|
||||
_ -> pure ()
|
||||
|
||||
printToTerminal :: ChatTerminal -> [StyledString] -> IO ()
|
||||
|
||||
Reference in New Issue
Block a user