@@ -687,9 +687,15 @@ allowConnectionAsync' c corrId connId confId ownConnInfo =
687
687
enqueueCommand c corrId connId (Just server) $ AClientCommand $ LET confId ownConnInfo
688
688
_ -> throwE $ CMD PROHIBITED " allowConnectionAsync"
689
689
690
+ -- TODO
691
+ -- Unlike `acceptContact` (synchronous version), `acceptContactAsync` uses `unacceptInvitation` in case of error,
692
+ -- because we're not taking lock here. In practice it is less likely to fail because it doesn't involve network IO,
693
+ -- and also it can't be triggered by user concurrently several times in a row. It could be improved similarly to
694
+ -- `acceptContact` by creating a new map for invitation locks and taking lock here, and removing `unacceptInvitation`
695
+ -- while marking invitation as accepted inside "lock level transaction" after successful `joinConnAsync`.
690
696
acceptContactAsync' :: AgentClient -> ACorrId -> Bool -> InvitationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AM ConnId
691
697
acceptContactAsync' c corrId enableNtfs invId ownConnInfo pqSupport subMode = do
692
- Invitation {contactConnId, connReq} <- withStore c ( ` getInvitation` invId)
698
+ Invitation {contactConnId, connReq} <- withStore c $ \ db -> getInvitation db " acceptContactAsync' " invId
693
699
withStore c (`getConn` contactConnId) >>= \ case
694
700
SomeConn _ (ContactConnection ConnData {userId} _) -> do
695
701
withStore' c $ \ db -> acceptInvitation db invId ownConnInfo
@@ -809,7 +815,7 @@ newConnToJoin c userId connId enableNtfs cReq pqSup = case cReq of
809
815
810
816
newConnToAccept :: AgentClient -> ConnId -> Bool -> ConfirmationId -> PQSupport -> AM ConnId
811
817
newConnToAccept c connId enableNtfs invId pqSup = do
812
- Invitation {connReq, contactConnId} <- withStore c ( ` getInvitation` invId)
818
+ Invitation {connReq, contactConnId} <- withStore c $ \ db -> getInvitation db " newConnToAccept " invId
813
819
withStore c (`getConn` contactConnId) >>= \ case
814
820
SomeConn _ (ContactConnection ConnData {userId} _) ->
815
821
newConnToJoin c userId connId enableNtfs connReq pqSup
@@ -941,13 +947,12 @@ allowConnection' c connId confId ownConnInfo = withConnLock c connId "allowConne
941
947
-- | Accept contact (ACPT command) in Reader monad
942
948
acceptContact' :: AgentClient -> ConnId -> Bool -> InvitationId -> ConnInfo -> PQSupport -> SubscriptionMode -> AM SndQueueSecured
943
949
acceptContact' c connId enableNtfs invId ownConnInfo pqSupport subMode = withConnLock c connId " acceptContact" $ do
944
- Invitation {contactConnId, connReq} <- withStore c ( ` getInvitation` invId)
950
+ Invitation {contactConnId, connReq} <- withStore c $ \ db -> getInvitation db " acceptContact' " invId
945
951
withStore c (`getConn` contactConnId) >>= \ case
946
952
SomeConn _ (ContactConnection ConnData {userId} _) -> do
953
+ sqSecured <- joinConn c userId connId enableNtfs connReq ownConnInfo pqSupport subMode
947
954
withStore' c $ \ db -> acceptInvitation db invId ownConnInfo
948
- joinConn c userId connId enableNtfs connReq ownConnInfo pqSupport subMode `catchAgentError` \ err -> do
949
- withStore' c (`unacceptInvitation` invId)
950
- throwE err
955
+ pure sqSecured
951
956
_ -> throwE $ CMD PROHIBITED " acceptContact"
952
957
953
958
-- | Reject contact (RJCT command) in Reader monad
0 commit comments