@@ -379,19 +379,20 @@ getConnShortLinkAsync c = withAgentEnv c .:: getConnShortLinkAsync' c
379379{-# INLINE getConnShortLinkAsync #-}
380380
381381-- | Enqueue JOIN command for a prepared connection.
382- joinConnectionAsync :: ConnectionModeI c => AgentClient -> ACorrId -> ConnId -> Bool -> ConnectionRequestUri c -> ConnInfo -> PQSupport -> SubscriptionMode -> AE ()
383- joinConnectionAsync c aCorrId connId enableNtfs cReqUri cInfo pqSup subMode =
384- withAgentEnv c $ joinConnAsync c aCorrId connId enableNtfs cReqUri cInfo pqSup subMode
382+ joinConnectionAsync :: ConnectionModeI c => AgentClient -> ACorrId -> Bool -> ConnId -> Bool -> ConnectionRequestUri c -> ConnInfo -> PQSupport -> SubscriptionMode -> AE ()
383+ joinConnectionAsync c aCorrId updateConn connId enableNtfs cReqUri cInfo pqSup subMode =
384+ withAgentEnv c $ joinConnAsync c aCorrId updateConn connId enableNtfs cReqUri cInfo pqSup subMode
385385{-# INLINE joinConnectionAsync #-}
386386
387387-- | Allow connection to continue after CONF notification (LET command), no synchronous response
388388allowConnectionAsync :: AgentClient -> ACorrId -> ConnId -> ConfirmationId -> ConnInfo -> AE ()
389389allowConnectionAsync c = withAgentEnv c .:: allowConnectionAsync' c
390390{-# INLINE allowConnectionAsync #-}
391391
392- -- | Accept contact after REQ notification (ACPT command) asynchronously, synchronous response is new connection id
393- acceptContactAsync :: AgentClient -> UserId -> ACorrId -> Bool -> ConfirmationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AE ConnId
394- acceptContactAsync c userId aCorrId enableNtfs = withAgentEnv c .:: acceptContactAsync' c userId aCorrId enableNtfs
392+ -- | Accept contact after REQ notification (ACPT command) asynchronously, for a prepared connection.
393+ acceptContactAsync :: AgentClient -> ACorrId -> ConnId -> Bool -> ConfirmationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AE ()
394+ acceptContactAsync c aCorrId connId enableNtfs invId ownConnInfo pqSupport subMode =
395+ withAgentEnv c $ acceptContactAsync' c aCorrId connId enableNtfs invId ownConnInfo pqSupport subMode
395396{-# INLINE acceptContactAsync #-}
396397
397398-- | Acknowledge message (ACK command) asynchronously, no synchronous response
@@ -856,17 +857,19 @@ newConnNoQueues c userId enableNtfs cMode pqSupport = do
856857 let cData = ConnData {userId, connId = " " , connAgentVersion, enableNtfs, lastExternalSndId = 0 , deleted = False , ratchetSyncState = RSOk , pqSupport}
857858 withStore c $ \ db -> createNewConn db g cData cMode
858859
859- joinConnAsync :: ConnectionModeI c => AgentClient -> ACorrId -> ConnId -> Bool -> ConnectionRequestUri c -> ConnInfo -> PQSupport -> SubscriptionMode -> AM ()
860- joinConnAsync c corrId connId enableNtfs cReqUri@ CRInvitationUri {} cInfo pqSup subMode =
860+ joinConnAsync :: ConnectionModeI c => AgentClient -> ACorrId -> Bool -> ConnId -> Bool -> ConnectionRequestUri c -> ConnInfo -> PQSupport -> SubscriptionMode -> AM ()
861+ joinConnAsync c corrId updateConn connId enableNtfs cReqUri@ CRInvitationUri {} cInfo pqSup subMode =
861862 lift (compatibleInvitationUri cReqUri) >>= \ case
862863 Just (_, Compatible (CR. E2ERatchetParams v _ _ _), Compatible connAgentVersion) -> do
863864 let pqSupport = pqSup `CR.pqSupportAnd` versionPQSupport_ connAgentVersion (Just v)
865+ when updateConn $ withStore' c $ \ db -> updateNewConnJoin db connId connAgentVersion pqSupport enableNtfs
864866 enqueueCommand c corrId connId Nothing $ AClientCommand $ JOIN enableNtfs (ACR sConnectionMode cReqUri) pqSupport subMode cInfo
865867 Nothing -> throwE $ AGENT A_VERSION
866- joinConnAsync c corrId connId enableNtfs cReqUri@ (CRContactUri _) cInfo pqSup subMode =
868+ joinConnAsync c corrId updateConn connId enableNtfs cReqUri@ (CRContactUri _) cInfo pqSup subMode =
867869 lift (compatibleContactUri cReqUri) >>= \ case
868870 Just (_, Compatible connAgentVersion) -> do
869871 let pqSupport = pqSup `CR.pqSupportAnd` versionPQSupport_ connAgentVersion Nothing
872+ when updateConn $ withStore' c $ \ db -> updateNewConnJoin db connId connAgentVersion pqSupport enableNtfs
870873 enqueueCommand c corrId connId Nothing $ AClientCommand $ JOIN enableNtfs (ACR sConnectionMode cReqUri) pqSupport subMode cInfo
871874 Nothing -> throwE $ AGENT A_VERSION
872875
@@ -883,15 +886,13 @@ allowConnectionAsync' c corrId connId confId ownConnInfo =
883886-- and also it can't be triggered by user concurrently several times in a row. It could be improved similarly to
884887-- `acceptContact` by creating a new map for invitation locks and taking lock here, and removing `unacceptInvitation`
885888-- while marking invitation as accepted inside "lock level transaction" after successful `joinConnAsync`.
886- acceptContactAsync' :: AgentClient -> UserId -> ACorrId -> Bool -> InvitationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AM ConnId
887- acceptContactAsync' c userId corrId enableNtfs invId ownConnInfo pqSupport subMode = do
889+ acceptContactAsync' :: AgentClient -> ACorrId -> ConnId -> Bool -> InvitationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AM ()
890+ acceptContactAsync' c corrId connId enableNtfs invId ownConnInfo pqSupport subMode = do
888891 Invitation {connReq} <- withStore c $ \ db -> getInvitation db " acceptContactAsync'" invId
889- connId <- newConnToJoin c userId " " enableNtfs connReq pqSupport
890892 withStore' c $ \ db -> acceptInvitation db invId ownConnInfo
891- joinConnAsync c corrId connId enableNtfs connReq ownConnInfo pqSupport subMode `catchAllErrors` \ err -> do
893+ joinConnAsync c corrId False connId enableNtfs connReq ownConnInfo pqSupport subMode `catchAllErrors` \ err -> do
892894 withStore' c (`unacceptInvitation` invId)
893895 throwE err
894- pure connId
895896
896897ackMessageAsync' :: AgentClient -> ACorrId -> ConnId -> AgentMsgId -> Maybe MsgReceiptInfo -> AM ()
897898ackMessageAsync' c corrId connId msgId rcptInfo_ = do
0 commit comments