ios: pending contact connections UI, core: delete connections on the server when deleting in UI/db (#565)

* ios: started pending connections UI

* ios: UI for pending contact connections complete

* this has to be getter, or it would break JSON parsing

* ios: update "initiated" status of connection
This commit is contained in:
Evgeny Poberezkin
2022-04-25 10:39:28 +01:00
committed by GitHub
parent db4731f19b
commit 89c36d42e2
14 changed files with 343 additions and 52 deletions
+5 -2
View File
@@ -365,8 +365,11 @@ processChatCommand = \case
unsetActive $ ActiveC localDisplayName
pure $ CRContactDeleted ct
gs -> throwChatError $ CEContactGroups ct gs
CTContactConnection ->
CRContactConnectionDeleted <$> withStore (\st -> deletePendingContactConnection st userId chatId)
CTContactConnection -> withChatLock . procCmd $ do
conn <- withStore $ \st -> getPendingContactConnection st userId chatId
withAgent $ \a -> deleteConnection a $ aConnId' conn
withStore $ \st -> deletePendingContactConnection st userId chatId
pure $ CRContactConnectionDeleted conn
CTGroup -> pure $ chatCmdError "not implemented"
CTContactRequest -> pure $ chatCmdError "not supported"
APIAcceptContact connReqId -> withUser $ \user@User {userId} -> withChatLock $ do
+33 -14
View File
@@ -152,6 +152,7 @@ module Simplex.Chat.Store
updateGroupChatItemsRead,
getSMPServers,
overwriteSMPServers,
getPendingContactConnection,
deletePendingContactConnection,
)
where
@@ -2727,21 +2728,39 @@ getContactConnectionChatPreviews_ db User {userId} _ =
stats = ChatStats {unreadCount = 0, minUnreadItemId = 0}
in AChat SCTContactConnection $ Chat (ContactConnection conn) [] stats
deletePendingContactConnection :: StoreMonad m => SQLiteStore -> UserId -> Int64 -> m PendingContactConnection
getPendingContactConnection :: StoreMonad m => SQLiteStore -> UserId -> Int64 -> m PendingContactConnection
getPendingContactConnection st userId connId =
liftIOEither . withTransaction st $ \db -> do
firstRow toPendingContactConnection (SEPendingConnectionNotFound connId) $
DB.query
db
[sql|
SELECT connection_id, agent_conn_id, conn_status, via_contact_uri_hash, created_at, updated_at
FROM connections
WHERE user_id = ?
AND connection_id = ?
AND conn_type = ?
AND contact_id IS NULL
AND conn_level = 0
AND via_contact IS NULL
|]
(userId, connId, ConnContact)
deletePendingContactConnection :: MonadUnliftIO m => SQLiteStore -> UserId -> Int64 -> m ()
deletePendingContactConnection st userId connId =
liftIOEither . withTransaction st $ \db -> runExceptT $ do
conn <-
ExceptT . firstRow toPendingContactConnection (SEPendingConnectionNotFound connId) $
DB.query
db
[sql|
SELECT connection_id, agent_conn_id, conn_status, via_contact_uri_hash, created_at, updated_at
FROM connections
WHERE user_id = ? AND conn_type = ? AND contact_id IS NULL AND conn_level = 0 AND via_contact IS NULL
|]
(userId, ConnContact)
liftIO $ DB.execute db "DELETE FROM connections WHERE connection_id = ?" (Only connId)
pure conn
liftIO . withTransaction st $ \db ->
DB.execute
db
[sql|
DELETE FROM connections
WHERE user_id = ?
AND connection_id = ?
AND conn_type = ?
AND contact_id IS NULL
AND conn_level = 0
AND via_contact IS NULL
|]
(userId, connId, ConnContact)
toPendingContactConnection :: (Int64, ConnId, ConnStatus, Maybe ByteString, UTCTime, UTCTime) -> PendingContactConnection
toPendingContactConnection (pccConnId, acId, pccConnStatus, connReqHash, createdAt, updatedAt) =
+3
View File
@@ -684,6 +684,9 @@ data PendingContactConnection = PendingContactConnection
}
deriving (Eq, Show, Generic)
aConnId' :: PendingContactConnection -> ConnId
aConnId' PendingContactConnection {pccAgentConnId = AgentConnId cId} = cId
instance ToJSON PendingContactConnection where toEncoding = J.genericToEncoding J.defaultOptions
data ConnStatus