cli: option to mark shown messages as read (off by default) (#3506)

* cli: option to mark shown messages as read (off by default)

* fix tests

* fix tests
This commit is contained in:
Evgeny Poberezkin 2023-12-03 15:42:26 +00:00 committed by GitHub
parent f94c0311c1
commit 6a9a67db14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 17 deletions

View File

@ -83,5 +83,6 @@ mkChatOpts BroadcastBotOpts {coreOptions} =
allowInstantFiles = True, allowInstantFiles = True,
autoAcceptFileSize = 0, autoAcceptFileSize = 0,
muteNotifications = True, muteNotifications = True,
markRead = False,
maintenance = False maintenance = False
} }

View File

@ -5,10 +5,10 @@
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
module Directory.Options module Directory.Options
( DirectoryOpts (..), ( DirectoryOpts (..),
getDirectoryOpts, getDirectoryOpts,
mkChatOpts, mkChatOpts,
) )
where where
import Options.Applicative import Options.Applicative
@ -35,8 +35,8 @@ directoryOpts appDir defaultDbFileName = do
<> help "Comma-separated list of super-users in the format CONTACT_ID:DISPLAY_NAME who will be allowed to manage the directory" <> help "Comma-separated list of super-users in the format CONTACT_ID:DISPLAY_NAME who will be allowed to manage the directory"
) )
directoryLog <- directoryLog <-
Just <$> Just
strOption <$> strOption
( long "directory-file" ( long "directory-file"
<> metavar "DIRECTORY_FILE" <> metavar "DIRECTORY_FILE"
<> help "Append only log for directory state" <> help "Append only log for directory state"
@ -81,5 +81,6 @@ mkChatOpts DirectoryOpts {coreOptions} =
allowInstantFiles = True, allowInstantFiles = True,
autoAcceptFileSize = 0, autoAcceptFileSize = 0,
muteNotifications = True, muteNotifications = True,
markRead = False,
maintenance = False maintenance = False
} }

View File

@ -42,6 +42,7 @@ data ChatOpts = ChatOpts
allowInstantFiles :: Bool, allowInstantFiles :: Bool,
autoAcceptFileSize :: Integer, autoAcceptFileSize :: Integer,
muteNotifications :: Bool, muteNotifications :: Bool,
markRead :: Bool,
maintenance :: Bool maintenance :: Bool
} }
@ -268,6 +269,12 @@ chatOptsP appDir defaultDbFileName = do
( long "mute" ( long "mute"
<> help "Mute notifications" <> help "Mute notifications"
) )
markRead <-
switch
( long "mark-read"
<> short 'r'
<> help "Mark shown messages as read"
)
maintenance <- maintenance <-
switch switch
( long "maintenance" ( long "maintenance"
@ -286,6 +293,7 @@ chatOptsP appDir defaultDbFileName = do
allowInstantFiles, allowInstantFiles,
autoAcceptFileSize, autoAcceptFileSize,
muteNotifications, muteNotifications,
markRead,
maintenance maintenance
} }

View File

@ -44,7 +44,7 @@ simplexChatTerminal cfg opts t =
handle checkDBKeyError . simplexChatCore cfg opts $ \u cc -> do handle checkDBKeyError . simplexChatCore cfg opts $ \u cc -> do
ct <- newChatTerminal t opts ct <- newChatTerminal t opts
when (firstTime cc) . printToTerminal ct $ chatWelcome u when (firstTime cc) . printToTerminal ct $ chatWelcome u
runChatTerminal ct cc runChatTerminal ct cc opts
checkDBKeyError :: SQLError -> IO () checkDBKeyError :: SQLError -> IO ()
checkDBKeyError e = case sqlError e of checkDBKeyError e = case sqlError e of
@ -53,5 +53,5 @@ checkDBKeyError e = case sqlError e of
exitFailure exitFailure
_ -> throwIO e _ -> throwIO e
runChatTerminal :: ChatTerminal -> ChatController -> IO () runChatTerminal :: ChatTerminal -> ChatController -> ChatOpts -> IO ()
runChatTerminal ct cc = raceAny_ [runTerminalInput ct cc, runTerminalOutput ct cc, runInputLoop ct cc] runChatTerminal ct cc opts = raceAny_ [runTerminalInput ct cc, runTerminalOutput ct cc opts, runInputLoop ct cc]

View File

@ -142,13 +142,13 @@ withTermLock ChatTerminal {termLock} action = do
action action
atomically $ putTMVar termLock () atomically $ putTMVar termLock ()
runTerminalOutput :: ChatTerminal -> ChatController -> IO () runTerminalOutput :: ChatTerminal -> ChatController -> ChatOpts -> IO ()
runTerminalOutput ct cc@ChatController {outputQ, showLiveItems, logFilePath} = do runTerminalOutput ct cc@ChatController {outputQ, showLiveItems, logFilePath} ChatOpts {markRead} = do
forever $ do forever $ do
(_, outputRH, r) <- atomically $ readTBQueue outputQ (_, outputRH, r) <- atomically $ readTBQueue outputQ
case r of case r of
CRNewChatItem u ci -> markChatItemRead u ci CRNewChatItem u ci -> when markRead $ markChatItemRead u ci
CRChatItemUpdated u ci -> markChatItemRead u ci CRChatItemUpdated u ci -> when markRead $ markChatItemRead u ci
CRRemoteHostConnected {remoteHost = RemoteHostInfo {remoteHostId}} -> getRemoteUser remoteHostId CRRemoteHostConnected {remoteHost = RemoteHostInfo {remoteHostId}} -> getRemoteUser remoteHostId
CRRemoteHostStopped {remoteHostId_} -> mapM_ removeRemoteUser remoteHostId_ CRRemoteHostStopped {remoteHostId_} -> mapM_ removeRemoteUser remoteHostId_
_ -> pure () _ -> pure ()

View File

@ -82,6 +82,7 @@ testOpts =
allowInstantFiles = True, allowInstantFiles = True,
autoAcceptFileSize = 0, autoAcceptFileSize = 0,
muteNotifications = True, muteNotifications = True,
markRead = True,
maintenance = False maintenance = False
} }
@ -174,7 +175,7 @@ startTestChat_ db cfg opts user = do
t <- withVirtualTerminal termSettings pure t <- withVirtualTerminal termSettings pure
ct <- newChatTerminal t opts ct <- newChatTerminal t opts
cc <- newChatController db (Just user) cfg opts cc <- newChatController db (Just user) cfg opts
chatAsync <- async . runSimplexChat opts user cc . const $ runChatTerminal ct chatAsync <- async . runSimplexChat opts user cc $ \_u cc' -> runChatTerminal ct cc' opts
atomically . unless (maintenance opts) $ readTVar (agentAsync cc) >>= \a -> when (isNothing a) retry atomically . unless (maintenance opts) $ readTVar (agentAsync cc) >>= \a -> when (isNothing a) retry
termQ <- newTQueueIO termQ <- newTQueueIO
termAsync <- async $ readTerminalOutput t termQ termAsync <- async $ readTerminalOutput t termQ

View File

@ -162,13 +162,13 @@ storedBindingsTest = testChat2 aliceProfile aliceDesktopProfile $ \mobile deskto
desktop ##> "/list remote hosts" desktop ##> "/list remote hosts"
desktop <## "Remote hosts:" desktop <## "Remote hosts:"
desktop <## "1. Mobile (connected) [lo 127.0.0.1:52230]" desktop <##. "1. Mobile (connected) ["
stopDesktop mobile desktop stopDesktop mobile desktop
desktop ##> "/list remote hosts" desktop ##> "/list remote hosts"
desktop <## "Remote hosts:" desktop <## "Remote hosts:"
desktop <## "1. Mobile [lo 127.0.0.1:52230]" desktop <##. "1. Mobile ["
-- TODO: more parser tests -- TODO: more parser tests
remoteMessageTest :: HasCallStack => FilePath -> IO () remoteMessageTest :: HasCallStack => FilePath -> IO ()
remoteMessageTest = testChat3 aliceProfile aliceDesktopProfile bobProfile $ \mobile desktop bob -> do remoteMessageTest = testChat3 aliceProfile aliceDesktopProfile bobProfile $ \mobile desktop bob -> do