From 3808b7415b5f95ed6e5868509dd4fbdfb2b8adef Mon Sep 17 00:00:00 2001 From: JRoberts <8711996+jr-simplex@users.noreply.github.com> Date: Mon, 3 Oct 2022 17:44:56 +0400 Subject: [PATCH] core: allow to set chat item ttl when chat is stopped (#1165) --- src/Simplex/Chat.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index f2110e0f5c..6e61895c52 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -641,7 +641,7 @@ processChatCommand = \case ChatConfig {defaultServers = InitialAgentServers {smp = defaultSMPServers}} <- asks config withAgent $ \a -> setSMPServers a (fromMaybe defaultSMPServers (nonEmpty smpServers)) pure CRCmdOk - APISetChatItemTTL newTTL_ -> withUser $ \user -> withChatLock $ do + APISetChatItemTTL newTTL_ -> withUser' $ \user -> withChatLock $ do case newTTL_ of Nothing -> do withStore' $ \db -> setChatItemTTL db user newTTL_ @@ -652,7 +652,7 @@ processChatCommand = \case setExpireCIs False expireChatItems user newTTL True withStore' $ \db -> setChatItemTTL db user newTTL_ - setExpireCIs True + whenM chatStarted $ setExpireCIs True pure CRCmdOk APIGetChatItemTTL -> CRChatItemTTL <$> withUser (\user -> withStore' (`getChatItemTTL` user)) APISetNetworkConfig cfg -> withUser' $ \_ -> withAgent (`setNetworkConfig` cfg) $> CRCmdOk @@ -2804,8 +2804,9 @@ withUser' action = withUser :: ChatMonad m => (User -> m a) -> m a withUser action = withUser' $ \user -> ifM chatStarted (action user) (throwChatError CEChatNotStarted) - where - chatStarted = fmap isJust . readTVarIO =<< asks agentAsync + +chatStarted :: ChatMonad m => m Bool +chatStarted = fmap isJust . readTVarIO =<< asks agentAsync withAgent :: ChatMonad m => (AgentClient -> ExceptT AgentErrorType m a) -> m a withAgent action =