diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index cb7fc17af..5e3d2f0da 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -933,7 +933,7 @@ processChatCommand = \case deleteFilesAndConns user filesInfo when (contactReady ct && contactActive ct && notify) $ void (sendDirectContactMessage ct XDirectDel) `catchChatError` const (pure ()) - contactConnIds <- map aConnId <$> withStore (\db -> getContactConnections db userId ct) + contactConnIds <- map aConnId <$> withStore' (\db -> getContactConnections db userId ct) deleteAgentConnectionsAsync user contactConnIds -- functions below are called in separate transactions to prevent crashes on android -- (possibly, race condition on integrity check?) @@ -976,7 +976,7 @@ processChatCommand = \case withStore' (\db -> checkContactHasGroups db user ct) >>= \case Just _ -> pure [] Nothing -> do - conns <- withStore $ \db -> getContactConnections db userId ct + conns <- withStore' $ \db -> getContactConnections db userId ct withStore' (\db -> setContactDeleted db user ct) `catchChatError` (toView . CRChatError (Just user)) pure $ map aConnId conns @@ -4496,7 +4496,7 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do then do checkIntegrityCreateItem (CDDirectRcv c) msgMeta ct' <- withStore' $ \db -> updateContactStatus db user c CSDeleted - contactConns <- withStore $ \db -> getContactConnections db userId ct' + contactConns <- withStore' $ \db -> getContactConnections db userId ct' deleteAgentConnectionsAsync user $ map aConnId contactConns forM_ contactConns $ \conn -> withStore' $ \db -> updateConnectionStatus db conn ConnDeleted activeConn' <- forM (contactConn ct') $ \conn -> pure conn {connStatus = ConnDeleted} @@ -4505,7 +4505,7 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do toView $ CRNewChatItem user (AChatItem SCTDirect SMDRcv (DirectChat ct'') ci) toView $ CRContactDeletedByContact user ct'' else do - contactConns <- withStore $ \db -> getContactConnections db userId c + contactConns <- withStore' $ \db -> getContactConnections db userId c deleteAgentConnectionsAsync user $ map aConnId contactConns withStore' $ \db -> deleteContact db user c diff --git a/src/Simplex/Chat/Store/Direct.hs b/src/Simplex/Chat/Store/Direct.hs index df346948e..bfc29fcd2 100644 --- a/src/Simplex/Chat/Store/Direct.hs +++ b/src/Simplex/Chat/Store/Direct.hs @@ -723,7 +723,7 @@ getPendingContactConnections db User {userId} = do |] [":user_id" := userId, ":conn_type" := ConnContact] -getContactConnections :: DB.Connection -> UserId -> Contact -> ExceptT StoreError IO [Connection] +getContactConnections :: DB.Connection -> UserId -> Contact -> IO [Connection] getContactConnections db userId Contact {contactId} = connections =<< liftIO getConnections_ where @@ -739,7 +739,7 @@ getContactConnections db userId Contact {contactId} = WHERE c.user_id = ? AND ct.user_id = ? AND ct.contact_id = ? |] (userId, userId, contactId) - connections [] = throwError $ SEContactNotFound contactId + connections [] = pure [] connections rows = pure $ map toConnection rows getConnectionById :: DB.Connection -> User -> Int64 -> ExceptT StoreError IO Connection diff --git a/tests/ChatTests/Profiles.hs b/tests/ChatTests/Profiles.hs index 3a38a1613..0a45a74ad 100644 --- a/tests/ChatTests/Profiles.hs +++ b/tests/ChatTests/Profiles.hs @@ -779,6 +779,12 @@ testPlanAddressContactViaAddress = void $ withCCUser bob $ \user -> withCCTransaction bob $ \db -> runExceptT $ createContact db user profile bob @@@ [("@alice", "")] + bob ##> "/delete @alice" + bob <## "alice: contact is deleted" + + void $ withCCUser bob $ \user -> withCCTransaction bob $ \db -> runExceptT $ createContact db user profile + bob @@@ [("@alice", "")] + bob ##> ("/_connect plan 1 " <> cLink) bob <## "contact address: known contact without connection alice"