From 88645cb00323b167ecaadb08a4d71d32dff1fda3 Mon Sep 17 00:00:00 2001 From: JRoberts <8711996+jr-simplex@users.noreply.github.com> Date: Fri, 7 Oct 2022 13:53:05 +0400 Subject: [PATCH] core: check chat store hasn't changed in APISetChatItemTTL (#1182) --- src/Simplex/Chat.hs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index da3ecb35fb..914eeaa76b 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -642,19 +642,21 @@ 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 - case newTTL_ of - Nothing -> do - withStore' $ \db -> setChatItemTTL db user newTTL_ - setExpireCIs False - Just newTTL -> do - oldTTL <- withStore' (`getChatItemTTL` user) - when (maybe True (newTTL <) oldTTL) $ do - setExpireCIs False - expireChatItems user newTTL True - withStore' $ \db -> setChatItemTTL db user newTTL_ - whenM chatStarted $ setExpireCIs True - pure CRCmdOk + APISetChatItemTTL newTTL_ -> withUser' $ \user -> + checkStoreNotChanged $ + withChatLock $ do + case newTTL_ of + Nothing -> do + withStore' $ \db -> setChatItemTTL db user newTTL_ + setExpireCIs False + Just newTTL -> do + oldTTL <- withStore' (`getChatItemTTL` user) + when (maybe True (newTTL <) oldTTL) $ do + setExpireCIs False + expireChatItems user newTTL True + withStore' $ \db -> setChatItemTTL db user newTTL_ + whenM chatStarted $ setExpireCIs True + pure CRCmdOk APIGetChatItemTTL -> CRChatItemTTL <$> withUser (\user -> withStore' (`getChatItemTTL` user)) APISetNetworkConfig cfg -> withUser' $ \_ -> withAgent (`setNetworkConfig` cfg) $> CRCmdOk APIGetNetworkConfig -> CRNetworkConfig <$> withUser' (\_ -> withAgent getNetworkConfig)