From 1459a0613a093cf5758fbf3f79a36c8223bfb5ca Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Thu, 25 Aug 2022 12:17:55 +0100 Subject: [PATCH] set invitation as not accepted in case of join error (#505) * set invitation as not accepted in case of join error * remove unused name --- src/Simplex/Messaging/Agent.hs | 4 +++- src/Simplex/Messaging/Agent/Store/SQLite.hs | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Simplex/Messaging/Agent.hs b/src/Simplex/Messaging/Agent.hs index 7cff667d5..4ad44ef4a 100644 --- a/src/Simplex/Messaging/Agent.hs +++ b/src/Simplex/Messaging/Agent.hs @@ -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 diff --git a/src/Simplex/Messaging/Agent/Store/SQLite.hs b/src/Simplex/Messaging/Agent/Store/SQLite.hs index 3e10a1def..25316fa1a 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite.hs @@ -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