diff --git a/src/Simplex/Messaging/Agent/NtfSubSupervisor.hs b/src/Simplex/Messaging/Agent/NtfSubSupervisor.hs index 4decd8c93..166c21486 100644 --- a/src/Simplex/Messaging/Agent/NtfSubSupervisor.hs +++ b/src/Simplex/Messaging/Agent/NtfSubSupervisor.hs @@ -247,14 +247,16 @@ runNtfSMPWorker c srv doWork = forever $ do (rcvNtfPubDhKey, rcvNtfPrivDhKey) <- liftIO C.generateKeyPair' (notifierId, rcvNtfSrvPubDhKey) <- enableQueueNotifications c rq ntfPublicKey rcvNtfPubDhKey let rcvNtfDhSecret = C.dh' rcvNtfSrvPubDhKey rcvNtfPrivDhKey - withStore' c $ \st -> do - setRcvQueueNtfCreds st connId ClientNtfCreds {ntfPublicKey, ntfPrivateKey, notifierId, rcvNtfDhSecret} - updateNtfSubscription st sub {ntfQueueId = Just notifierId, ntfSubStatus = NASKey} (NtfSubNTFAction NSACreate) ts + withStore' c $ \db -> do + setRcvQueueNtfCreds db connId $ Just ClientNtfCreds {ntfPublicKey, ntfPrivateKey, notifierId, rcvNtfDhSecret} + updateNtfSubscription db sub {ntfQueueId = Just notifierId, ntfSubStatus = NASKey} (NtfSubNTFAction NSACreate) ts ns <- asks ntfSupervisor atomically $ sendNtfSubCommand ns (connId, NSCNtfWorker ntfServer) _ -> ntfInternalError c connId "NSASmpKey - no active token" NSASmpDelete -> do - rq_ <- withStore' c (`getRcvQueue` connId) + rq_ <- withStore' c $ \db -> do + setRcvQueueNtfCreds db connId Nothing + getRcvQueue db connId forM_ rq_ $ \rq -> disableQueueNotifications c rq withStore' c $ \db -> deleteNtfSubscription db connId diff --git a/src/Simplex/Messaging/Agent/Store/SQLite.hs b/src/Simplex/Messaging/Agent/Store/SQLite.hs index c4b92f2d5..bd28f365f 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite.hs @@ -352,8 +352,8 @@ getRcvQueue :: DB.Connection -> ConnId -> IO (Either StoreError RcvQueue) getRcvQueue db connId = maybe (Left SEConnNotFound) Right <$> getRcvQueueByConnId_ db connId -setRcvQueueNtfCreds :: DB.Connection -> ConnId -> ClientNtfCreds -> IO () -setRcvQueueNtfCreds db connId ClientNtfCreds {ntfPublicKey, ntfPrivateKey, notifierId, rcvNtfDhSecret} = +setRcvQueueNtfCreds :: DB.Connection -> ConnId -> Maybe ClientNtfCreds -> IO () +setRcvQueueNtfCreds db connId clientNtfCreds = DB.execute db [sql| @@ -361,7 +361,11 @@ setRcvQueueNtfCreds db connId ClientNtfCreds {ntfPublicKey, ntfPrivateKey, notif SET ntf_public_key = ?, ntf_private_key = ?, ntf_id = ?, rcv_ntf_dh_secret = ? WHERE conn_id = ? |] - (ntfPublicKey, ntfPrivateKey, notifierId, rcvNtfDhSecret, connId) + (ntfPublicKey_, ntfPrivateKey_, notifierId_, rcvNtfDhSecret_, connId) + where + (ntfPublicKey_, ntfPrivateKey_, notifierId_, rcvNtfDhSecret_) = case clientNtfCreds of + Just ClientNtfCreds {ntfPublicKey, ntfPrivateKey, notifierId, rcvNtfDhSecret} -> (Just ntfPublicKey, Just ntfPrivateKey, Just notifierId, Just rcvNtfDhSecret) + Nothing -> (Nothing, Nothing, Nothing, Nothing) createConfirmation :: DB.Connection -> TVar ChaChaDRG -> NewConfirmation -> IO (Either StoreError ConfirmationId) createConfirmation db gVar NewConfirmation {connId, senderConf = SMPConfirmation {senderKey, e2ePubKey, connInfo, smpReplyQueues}, ratchetState} =