core: fix deletion of contact without connections (#3327)
This commit is contained in:
parent
ee6bd0f839
commit
8722d35278
@ -933,7 +933,7 @@ processChatCommand = \case
|
|||||||
deleteFilesAndConns user filesInfo
|
deleteFilesAndConns user filesInfo
|
||||||
when (contactReady ct && contactActive ct && notify) $
|
when (contactReady ct && contactActive ct && notify) $
|
||||||
void (sendDirectContactMessage ct XDirectDel) `catchChatError` const (pure ())
|
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
|
deleteAgentConnectionsAsync user contactConnIds
|
||||||
-- functions below are called in separate transactions to prevent crashes on android
|
-- functions below are called in separate transactions to prevent crashes on android
|
||||||
-- (possibly, race condition on integrity check?)
|
-- (possibly, race condition on integrity check?)
|
||||||
@ -976,7 +976,7 @@ processChatCommand = \case
|
|||||||
withStore' (\db -> checkContactHasGroups db user ct) >>= \case
|
withStore' (\db -> checkContactHasGroups db user ct) >>= \case
|
||||||
Just _ -> pure []
|
Just _ -> pure []
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
conns <- withStore $ \db -> getContactConnections db userId ct
|
conns <- withStore' $ \db -> getContactConnections db userId ct
|
||||||
withStore' (\db -> setContactDeleted db user ct)
|
withStore' (\db -> setContactDeleted db user ct)
|
||||||
`catchChatError` (toView . CRChatError (Just user))
|
`catchChatError` (toView . CRChatError (Just user))
|
||||||
pure $ map aConnId conns
|
pure $ map aConnId conns
|
||||||
@ -4496,7 +4496,7 @@ processAgentMessageConn user@User {userId} corrId agentConnId agentMessage = do
|
|||||||
then do
|
then do
|
||||||
checkIntegrityCreateItem (CDDirectRcv c) msgMeta
|
checkIntegrityCreateItem (CDDirectRcv c) msgMeta
|
||||||
ct' <- withStore' $ \db -> updateContactStatus db user c CSDeleted
|
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
|
deleteAgentConnectionsAsync user $ map aConnId contactConns
|
||||||
forM_ contactConns $ \conn -> withStore' $ \db -> updateConnectionStatus db conn ConnDeleted
|
forM_ contactConns $ \conn -> withStore' $ \db -> updateConnectionStatus db conn ConnDeleted
|
||||||
activeConn' <- forM (contactConn ct') $ \conn -> pure conn {connStatus = 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 $ CRNewChatItem user (AChatItem SCTDirect SMDRcv (DirectChat ct'') ci)
|
||||||
toView $ CRContactDeletedByContact user ct''
|
toView $ CRContactDeletedByContact user ct''
|
||||||
else do
|
else do
|
||||||
contactConns <- withStore $ \db -> getContactConnections db userId c
|
contactConns <- withStore' $ \db -> getContactConnections db userId c
|
||||||
deleteAgentConnectionsAsync user $ map aConnId contactConns
|
deleteAgentConnectionsAsync user $ map aConnId contactConns
|
||||||
withStore' $ \db -> deleteContact db user c
|
withStore' $ \db -> deleteContact db user c
|
||||||
|
|
||||||
|
@ -723,7 +723,7 @@ getPendingContactConnections db User {userId} = do
|
|||||||
|]
|
|]
|
||||||
[":user_id" := userId, ":conn_type" := ConnContact]
|
[":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} =
|
getContactConnections db userId Contact {contactId} =
|
||||||
connections =<< liftIO getConnections_
|
connections =<< liftIO getConnections_
|
||||||
where
|
where
|
||||||
@ -739,7 +739,7 @@ getContactConnections db userId Contact {contactId} =
|
|||||||
WHERE c.user_id = ? AND ct.user_id = ? AND ct.contact_id = ?
|
WHERE c.user_id = ? AND ct.user_id = ? AND ct.contact_id = ?
|
||||||
|]
|
|]
|
||||||
(userId, userId, contactId)
|
(userId, userId, contactId)
|
||||||
connections [] = throwError $ SEContactNotFound contactId
|
connections [] = pure []
|
||||||
connections rows = pure $ map toConnection rows
|
connections rows = pure $ map toConnection rows
|
||||||
|
|
||||||
getConnectionById :: DB.Connection -> User -> Int64 -> ExceptT StoreError IO Connection
|
getConnectionById :: DB.Connection -> User -> Int64 -> ExceptT StoreError IO Connection
|
||||||
|
@ -779,6 +779,12 @@ testPlanAddressContactViaAddress =
|
|||||||
void $ withCCUser bob $ \user -> withCCTransaction bob $ \db -> runExceptT $ createContact db user profile
|
void $ withCCUser bob $ \user -> withCCTransaction bob $ \db -> runExceptT $ createContact db user profile
|
||||||
bob @@@ [("@alice", "")]
|
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 ##> ("/_connect plan 1 " <> cLink)
|
||||||
bob <## "contact address: known contact without connection alice"
|
bob <## "contact address: known contact without connection alice"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user