From 0622a52e0023a7f0b6cd14bd8a0ec85a75fa65e2 Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Fri, 26 Apr 2024 18:25:03 +0300 Subject: [PATCH] fix withCompletedCommand --- src/Simplex/Chat.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index a5ba74c9f8..acd9885377 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -4686,8 +4686,9 @@ processAgentMessageConn vr user@User {userId} corrId agentConnId agentMessage = withCompletedCommand :: forall e. AEntityI e => Connection -> ACommand 'Agent e -> (CommandData -> CM ()) -> CM () withCompletedCommand Connection {connId} agentMsg action = do let agentMsgTag = APCT (sAEntity @e) $ aCommandTag agentMsg - if agentMsgTag == APCT SAEConn OK_ && corrId /= "" - then markDelivery + pending_ <- mapM readTVarIO =<< atomically . TM.lookup acId =<< asks agentDeliveryStatuses + if agentMsgTag == APCT SAEConn OK_ && corrId /= "" && maybe False (M.member ackKey . pendingAcks) pending_ + then lift $ agentDeliveryStatus acId $ \ad@AgentDeliveryStatus {pendingAcks} -> ad {pendingAcks = M.adjust (const True) ackKey pendingAcks} else do cmdData_ <- withStore' $ \db -> getCommandDataByCorrId db user corrId case cmdData_ of @@ -4699,9 +4700,8 @@ processAgentMessageConn vr user@User {userId} corrId agentConnId agentMessage = Just CommandData {cmdId, cmdConnId = Nothing} -> err cmdId $ "no command connection id, corrId = " <> show corrId Nothing -> throwChatError . CEAgentCommandError $ "command not found, corrId = " <> show corrId where - markDelivery = do - let ackKey = decodeLatin1 $ strEncode corrId - lift $ agentDeliveryStatus (AgentConnId agentConnId) $ \ad@AgentDeliveryStatus {pendingAcks} -> ad {pendingAcks = M.adjust (const True) ackKey pendingAcks} + acId = AgentConnId agentConnId + ackKey = decodeLatin1 $ strEncode corrId err cmdId msg = do withStore' $ \db -> updateCommandStatus db user cmdId CSError throwChatError . CEAgentCommandError $ msg