From f3b0ca12c292080ba00a6472aab386246849dad7 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Thu, 10 Oct 2024 19:45:36 +0400 Subject: [PATCH] comment --- src/Simplex/Chat.hs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index f1be694d3b..f177dc615b 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -1783,12 +1783,17 @@ processChatCommand' vr = \case Just (agentV, pqSup') -> do let chatV = agentToChatVersion agentV dm <- encodeConnInfoPQ pqSup' chatV $ XInfo profileToSend - -- TODO conn prepare - -- search connection by link (cReq) - -- or, better, pass connId found by connectPlan? (Either AConnectionRequestUri DBConnectionId) connId <- withAgent $ \a -> prepareConnectionToJoin a (aUserId user) True cReq pqSup' - conn <- withFastStore' $ \db -> createDirectConnection db user connId cReq ConnJoined (incognitoProfile $> profileToSend) subMode chatV pqSup' - void $ withAgent $ \a -> joinConnection a (aUserId user) connId True cReq dm pqSup' subMode + conn@PendingContactConnection {pccConnId} <- withFastStore' $ \db -> createDirectConnection db user connId cReq ConnJoined (incognitoProfile $> profileToSend) subMode chatV pqSup' + -- TODO reuse connection record + -- try to get PendingContactConnection by link (reuse connectPlan?); + -- if it exists, pass its connId to joinConnection to reuse key and avoid AUTH error; + -- insead of deleting, cleanup should mark connection in a way so that it's filtered out of chat list + void (withAgent $ \a -> joinConnection a (aUserId user) connId True cReq dm pqSup' subMode) + `catchChatError` \e -> do + withFastStore' $ \db -> deleteConnectionRecord db user pccConnId + withAgent $ \a -> deleteConnectionAsync a False connId + throwError e pure $ CRSentConfirmation user conn APIConnect userId incognito (Just (ACR SCMContact cReq)) -> withUserId userId $ \user -> connectViaContact user incognito cReq APIConnect _ _ Nothing -> throwChatError CEInvalidConnReq