set invitation as not accepted in case of join error (#505)

* set invitation as not accepted in case of join error

* remove unused name
This commit is contained in:
Evgeny Poberezkin
2022-08-25 12:17:55 +01:00
committed by GitHub
parent a7b39b710c
commit 1459a0613a
2 changed files with 8 additions and 1 deletions
+3 -1
View File
@@ -391,7 +391,9 @@ acceptContact' c connId enableNtfs invId ownConnInfo = do
withStore c (`getConn` contactConnId) >>= \case
SomeConn _ ContactConnection {} -> do
withStore' c $ \db -> acceptInvitation db invId ownConnInfo
joinConn c connId enableNtfs connReq ownConnInfo
joinConn c connId enableNtfs connReq ownConnInfo `catchError` \err -> do
withStore' c (`unacceptInvitation` invId)
throwError err
_ -> throwError $ CMD PROHIBITED
-- | Reject contact (RJCT command) in Reader monad
@@ -47,6 +47,7 @@ module Simplex.Messaging.Agent.Store.SQLite
createInvitation,
getInvitation,
acceptInvitation,
unacceptInvitation,
deleteInvitation,
-- Messages
updateRcvIds,
@@ -504,6 +505,10 @@ acceptInvitation db invitationId ownConnInfo =
":invitation_id" := invitationId
]
unacceptInvitation :: DB.Connection -> InvitationId -> IO ()
unacceptInvitation db invitationId =
DB.execute db "UPDATE conn_invitations SET accepted = 0, own_conn_info = NULL WHERE invitation_id = ?" (Only invitationId)
deleteInvitation :: DB.Connection -> ConnId -> InvitationId -> IO (Either StoreError ())
deleteInvitation db contactConnId invId =
getConn db contactConnId $>>= \case