@@ -343,8 +343,8 @@ allowConnectionAsync c = withAgentEnv c .:: allowConnectionAsync' c
343343{-# INLINE allowConnectionAsync #-}
344344
345345-- | Accept contact after REQ notification (ACPT command) asynchronously, synchronous response is new connection id
346- acceptContactAsync :: AgentClient -> ACorrId -> Bool -> ConfirmationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AE ConnId
347- acceptContactAsync c aCorrId enableNtfs = withAgentEnv c .:: acceptContactAsync' c aCorrId enableNtfs
346+ acceptContactAsync :: AgentClient -> UserId -> ACorrId -> Bool -> ConfirmationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AE ConnId
347+ acceptContactAsync c userId aCorrId enableNtfs = withAgentEnv c .:: acceptContactAsync' c userId aCorrId enableNtfs
348348{-# INLINE acceptContactAsync #-}
349349
350350-- | Acknowledge message (ACK command) asynchronously, no synchronous response
@@ -406,8 +406,8 @@ prepareConnectionToJoin c userId enableNtfs = withAgentEnv c .: newConnToJoin c
406406{-# INLINE prepareConnectionToJoin #-}
407407
408408-- | Create SMP agent connection without queue (to be joined with acceptContact passing invitation ID).
409- prepareConnectionToAccept :: AgentClient -> Bool -> ConfirmationId -> PQSupport -> AE ConnId
410- prepareConnectionToAccept c enableNtfs = withAgentEnv c .: newConnToAccept c " " enableNtfs
409+ prepareConnectionToAccept :: AgentClient -> UserId -> Bool -> ConfirmationId -> PQSupport -> AE ConnId
410+ prepareConnectionToAccept c userId enableNtfs = withAgentEnv c .: newConnToAccept c userId " " enableNtfs
411411{-# INLINE prepareConnectionToAccept #-}
412412
413413-- | Join SMP agent connection (JOIN command).
@@ -421,13 +421,13 @@ allowConnection c = withAgentEnv c .:. allowConnection' c
421421{-# INLINE allowConnection #-}
422422
423423-- | Accept contact after REQ notification (ACPT command)
424- acceptContact :: AgentClient -> ConnId -> Bool -> ConfirmationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AE (SndQueueSecured , Maybe ClientServiceId )
425- acceptContact c connId enableNtfs = withAgentEnv c .:: acceptContact' c connId enableNtfs
424+ acceptContact :: AgentClient -> UserId -> ConnId -> Bool -> ConfirmationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AE (SndQueueSecured , Maybe ClientServiceId )
425+ acceptContact c userId connId enableNtfs = withAgentEnv c .:: acceptContact' c userId connId enableNtfs
426426{-# INLINE acceptContact #-}
427427
428428-- | Reject contact (RJCT command)
429- rejectContact :: AgentClient -> ConnId -> ConfirmationId -> AE ()
430- rejectContact c = withAgentEnv c .: rejectContact' c
429+ rejectContact :: AgentClient -> ConfirmationId -> AE ()
430+ rejectContact c = withAgentEnv c . rejectContact' c
431431{-# INLINE rejectContact #-}
432432
433433-- | Subscribe to receive connection messages (SUB command)
@@ -770,16 +770,13 @@ allowConnectionAsync' c corrId connId confId ownConnInfo =
770770-- and also it can't be triggered by user concurrently several times in a row. It could be improved similarly to
771771-- `acceptContact` by creating a new map for invitation locks and taking lock here, and removing `unacceptInvitation`
772772-- while marking invitation as accepted inside "lock level transaction" after successful `joinConnAsync`.
773- acceptContactAsync' :: AgentClient -> ACorrId -> Bool -> InvitationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AM ConnId
774- acceptContactAsync' c corrId enableNtfs invId ownConnInfo pqSupport subMode = do
775- Invitation {contactConnId, connReq} <- withStore c $ \ db -> getInvitation db " acceptContactAsync'" invId
776- withStore c (`getConn` contactConnId) >>= \ case
777- SomeConn _ (ContactConnection ConnData {userId} _) -> do
778- withStore' c $ \ db -> acceptInvitation db invId ownConnInfo
779- joinConnAsync c userId corrId enableNtfs connReq ownConnInfo pqSupport subMode `catchAgentError` \ err -> do
780- withStore' c (`unacceptInvitation` invId)
781- throwE err
782- _ -> throwE $ CMD PROHIBITED " acceptContactAsync"
773+ acceptContactAsync' :: AgentClient -> UserId -> ACorrId -> Bool -> InvitationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AM ConnId
774+ acceptContactAsync' c userId corrId enableNtfs invId ownConnInfo pqSupport subMode = do
775+ Invitation {connReq} <- withStore c $ \ db -> getInvitation db " acceptContactAsync'" invId
776+ withStore' c $ \ db -> acceptInvitation db invId ownConnInfo
777+ joinConnAsync c userId corrId enableNtfs connReq ownConnInfo pqSupport subMode `catchAgentError` \ err -> do
778+ withStore' c (`unacceptInvitation` invId)
779+ throwE err
783780
784781ackMessageAsync' :: AgentClient -> ACorrId -> ConnId -> AgentMsgId -> Maybe MsgReceiptInfo -> AM ()
785782ackMessageAsync' c corrId connId msgId rcptInfo_ = do
@@ -1036,13 +1033,10 @@ newConnToJoin c userId connId enableNtfs cReq pqSup = case cReq of
10361033 cData = ConnData {userId, connId, connAgentVersion, enableNtfs, lastExternalSndId = 0 , deleted = False , ratchetSyncState = RSOk , pqSupport}
10371034 withStore c $ \ db -> createNewConn db g cData SCMInvitation
10381035
1039- newConnToAccept :: AgentClient -> ConnId -> Bool -> ConfirmationId -> PQSupport -> AM ConnId
1040- newConnToAccept c connId enableNtfs invId pqSup = do
1041- Invitation {connReq, contactConnId} <- withStore c $ \ db -> getInvitation db " newConnToAccept" invId
1042- withStore c (`getConn` contactConnId) >>= \ case
1043- SomeConn _ (ContactConnection ConnData {userId} _) ->
1044- newConnToJoin c userId connId enableNtfs connReq pqSup
1045- _ -> throwE $ CMD PROHIBITED " newConnToAccept"
1036+ newConnToAccept :: AgentClient -> UserId -> ConnId -> Bool -> ConfirmationId -> PQSupport -> AM ConnId
1037+ newConnToAccept c userId connId enableNtfs invId pqSup = do
1038+ Invitation {connReq} <- withStore c $ \ db -> getInvitation db " newConnToAccept" invId
1039+ newConnToJoin c userId connId enableNtfs connReq pqSup
10461040
10471041joinConn :: AgentClient -> UserId -> ConnId -> Bool -> ConnectionRequestUri c -> ConnInfo -> PQSupport -> SubscriptionMode -> AM (SndQueueSecured , Maybe ClientServiceId )
10481042joinConn c userId connId enableNtfs cReq cInfo pqSupport subMode = do
@@ -1220,20 +1214,17 @@ allowConnection' c connId confId ownConnInfo = withConnLock c connId "allowConne
12201214 _ -> throwE $ CMD PROHIBITED " allowConnection"
12211215
12221216-- | Accept contact (ACPT command) in Reader monad
1223- acceptContact' :: AgentClient -> ConnId -> Bool -> InvitationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AM (SndQueueSecured , Maybe ClientServiceId )
1224- acceptContact' c connId enableNtfs invId ownConnInfo pqSupport subMode = withConnLock c connId " acceptContact" $ do
1225- Invitation {contactConnId, connReq} <- withStore c $ \ db -> getInvitation db " acceptContact'" invId
1226- withStore c (`getConn` contactConnId) >>= \ case
1227- SomeConn _ (ContactConnection ConnData {userId} _) -> do
1228- r <- joinConn c userId connId enableNtfs connReq ownConnInfo pqSupport subMode
1229- withStore' c $ \ db -> acceptInvitation db invId ownConnInfo
1230- pure r
1231- _ -> throwE $ CMD PROHIBITED " acceptContact"
1217+ acceptContact' :: AgentClient -> UserId -> ConnId -> Bool -> InvitationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AM (SndQueueSecured , Maybe ClientServiceId )
1218+ acceptContact' c userId connId enableNtfs invId ownConnInfo pqSupport subMode = withConnLock c connId " acceptContact" $ do
1219+ Invitation {connReq} <- withStore c $ \ db -> getInvitation db " acceptContact'" invId
1220+ r <- joinConn c userId connId enableNtfs connReq ownConnInfo pqSupport subMode
1221+ withStore' c $ \ db -> acceptInvitation db invId ownConnInfo
1222+ pure r
12321223
12331224-- | Reject contact (RJCT command) in Reader monad
1234- rejectContact' :: AgentClient -> ConnId -> InvitationId -> AM ()
1235- rejectContact' c contactConnId invId =
1236- withStore c $ \ db -> deleteInvitation db contactConnId invId
1225+ rejectContact' :: AgentClient -> InvitationId -> AM ()
1226+ rejectContact' c invId =
1227+ withStore' c $ \ db -> deleteInvitation db invId
12371228{-# INLINE rejectContact' #-}
12381229
12391230-- | Subscribe to receive connection messages (SUB command) in Reader monad
0 commit comments