mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 12:19:54 +00:00
core: fix change connection user (#5992)
* core: fix change connection user * plans
This commit is contained in:
parent
c08189108e
commit
3d22b738d8
6 changed files with 34 additions and 54 deletions
|
@ -1671,25 +1671,10 @@ processChatCommand' vr = \case
|
||||||
case (pccConnStatus, connLinkInv) of
|
case (pccConnStatus, connLinkInv) of
|
||||||
(ConnNew, Just (CCLink cReqInv _)) -> do
|
(ConnNew, Just (CCLink cReqInv _)) -> do
|
||||||
newUser <- privateGetUser newUserId
|
newUser <- privateGetUser newUserId
|
||||||
conn' <- ifM (canKeepLink cReqInv newUser) (updateConnRecord user conn newUser) (recreateConn user conn newUser)
|
conn' <- recreateConn user conn newUser
|
||||||
pure $ CRConnectionUserChanged user conn conn' newUser
|
pure $ CRConnectionUserChanged user conn conn' newUser
|
||||||
_ -> throwChatError CEConnectionUserChangeProhibited
|
_ -> throwChatError CEConnectionUserChangeProhibited
|
||||||
where
|
where
|
||||||
canKeepLink :: ConnReqInvitation -> User -> CM Bool
|
|
||||||
canKeepLink (CRInvitationUri crData _) newUser = do
|
|
||||||
let ConnReqUriData {crSmpQueues = q :| _} = crData
|
|
||||||
SMPQueueUri {queueAddress = SMPQueueAddress {smpServer}} = q
|
|
||||||
newUserServers <-
|
|
||||||
map protoServer' . L.filter (\ServerCfg {enabled} -> enabled)
|
|
||||||
<$> getKnownAgentServers SPSMP newUser
|
|
||||||
pure $ smpServer `elem` newUserServers
|
|
||||||
updateConnRecord user@User {userId} conn@PendingContactConnection {customUserProfileId} newUser = do
|
|
||||||
withAgent $ \a -> changeConnectionUser a (aUserId user) (aConnId' conn) (aUserId newUser)
|
|
||||||
withFastStore' $ \db -> do
|
|
||||||
conn' <- updatePCCUser db userId conn newUserId
|
|
||||||
forM_ customUserProfileId $ \profileId ->
|
|
||||||
deletePCCIncognitoProfile db user profileId
|
|
||||||
pure conn'
|
|
||||||
recreateConn user conn@PendingContactConnection {customUserProfileId, connLinkInv} newUser = do
|
recreateConn user conn@PendingContactConnection {customUserProfileId, connLinkInv} newUser = do
|
||||||
subMode <- chatReadVar subscriptionMode
|
subMode <- chatReadVar subscriptionMode
|
||||||
let userData = shortLinkUserData $ isJust $ connShortLink =<< connLinkInv
|
let userData = shortLinkUserData $ isJust $ connShortLink =<< connLinkInv
|
||||||
|
|
|
@ -66,7 +66,6 @@ module Simplex.Chat.Store.Direct
|
||||||
updateContactAccepted,
|
updateContactAccepted,
|
||||||
getUserByContactRequestId,
|
getUserByContactRequestId,
|
||||||
getPendingContactConnections,
|
getPendingContactConnections,
|
||||||
updatePCCUser,
|
|
||||||
getContactConnections,
|
getContactConnections,
|
||||||
getConnectionById,
|
getConnectionById,
|
||||||
getConnectionsContacts,
|
getConnectionsContacts,
|
||||||
|
@ -440,19 +439,6 @@ updatePCCIncognito db User {userId} conn customUserProfileId = do
|
||||||
(customUserProfileId, updatedAt, userId, pccConnId conn)
|
(customUserProfileId, updatedAt, userId, pccConnId conn)
|
||||||
pure (conn :: PendingContactConnection) {customUserProfileId, updatedAt}
|
pure (conn :: PendingContactConnection) {customUserProfileId, updatedAt}
|
||||||
|
|
||||||
updatePCCUser :: DB.Connection -> UserId -> PendingContactConnection -> UserId -> IO PendingContactConnection
|
|
||||||
updatePCCUser db userId conn newUserId = do
|
|
||||||
updatedAt <- getCurrentTime
|
|
||||||
DB.execute
|
|
||||||
db
|
|
||||||
[sql|
|
|
||||||
UPDATE connections
|
|
||||||
SET user_id = ?, custom_user_profile_id = NULL, updated_at = ?
|
|
||||||
WHERE user_id = ? AND connection_id = ?
|
|
||||||
|]
|
|
||||||
(newUserId, updatedAt, userId, pccConnId conn)
|
|
||||||
pure (conn :: PendingContactConnection) {customUserProfileId = Nothing, updatedAt}
|
|
||||||
|
|
||||||
deletePCCIncognitoProfile :: DB.Connection -> User -> ProfileId -> IO ()
|
deletePCCIncognitoProfile :: DB.Connection -> User -> ProfileId -> IO ()
|
||||||
deletePCCIncognitoProfile db User {userId} profileId =
|
deletePCCIncognitoProfile db User {userId} profileId =
|
||||||
DB.execute
|
DB.execute
|
||||||
|
|
|
@ -1071,10 +1071,6 @@ Query: UPDATE connections SET smp_agent_version = ? WHERE conn_id = ?
|
||||||
Plan:
|
Plan:
|
||||||
SEARCH connections USING PRIMARY KEY (conn_id=?)
|
SEARCH connections USING PRIMARY KEY (conn_id=?)
|
||||||
|
|
||||||
Query: UPDATE connections SET user_id = ? WHERE conn_id = ? and user_id = ?
|
|
||||||
Plan:
|
|
||||||
SEARCH connections USING PRIMARY KEY (conn_id=?)
|
|
||||||
|
|
||||||
Query: UPDATE messages SET msg_body = x'' WHERE conn_id = ? AND internal_id = ?
|
Query: UPDATE messages SET msg_body = x'' WHERE conn_id = ? AND internal_id = ?
|
||||||
Plan:
|
Plan:
|
||||||
SEARCH messages USING PRIMARY KEY (conn_id=? AND internal_id=?)
|
SEARCH messages USING PRIMARY KEY (conn_id=? AND internal_id=?)
|
||||||
|
|
|
@ -4215,14 +4215,6 @@ Query:
|
||||||
Plan:
|
Plan:
|
||||||
SEARCH connections USING INTEGER PRIMARY KEY (rowid=?)
|
SEARCH connections USING INTEGER PRIMARY KEY (rowid=?)
|
||||||
|
|
||||||
Query:
|
|
||||||
UPDATE connections
|
|
||||||
SET user_id = ?, custom_user_profile_id = NULL, updated_at = ?
|
|
||||||
WHERE user_id = ? AND connection_id = ?
|
|
||||||
|
|
||||||
Plan:
|
|
||||||
SEARCH connections USING INTEGER PRIMARY KEY (rowid=?)
|
|
||||||
|
|
||||||
Query:
|
Query:
|
||||||
UPDATE contact_profiles
|
UPDATE contact_profiles
|
||||||
SET contact_link = ?, updated_at = ?
|
SET contact_link = ?, updated_at = ?
|
||||||
|
|
|
@ -1747,10 +1747,9 @@ viewConnectionIncognitoUpdated PendingContactConnection {pccConnId, customUserPr
|
||||||
| otherwise = ["connection " <> sShow pccConnId <> " changed to non incognito"]
|
| otherwise = ["connection " <> sShow pccConnId <> " changed to non incognito"]
|
||||||
|
|
||||||
viewConnectionUserChanged :: User -> PendingContactConnection -> User -> PendingContactConnection -> [StyledString]
|
viewConnectionUserChanged :: User -> PendingContactConnection -> User -> PendingContactConnection -> [StyledString]
|
||||||
viewConnectionUserChanged User {localDisplayName = n} PendingContactConnection {pccConnId, connLinkInv} User {localDisplayName = n'} PendingContactConnection {connLinkInv = connLinkInv'} =
|
viewConnectionUserChanged User {localDisplayName = n} PendingContactConnection {pccConnId} User {localDisplayName = n'} PendingContactConnection {connLinkInv = connLinkInv'} =
|
||||||
case (connLinkInv, connLinkInv') of
|
case connLinkInv' of
|
||||||
(Just ccLink, Just ccLink')
|
Just ccLink' -> [userChangedStr <> ", new link:"] <> newLink ccLink'
|
||||||
| ccLink /= ccLink' -> [userChangedStr <> ", new link:"] <> newLink ccLink'
|
|
||||||
_ -> [userChangedStr]
|
_ -> [userChangedStr]
|
||||||
where
|
where
|
||||||
userChangedStr = "connection " <> sShow pccConnId <> " changed from user " <> plain n <> " to user " <> plain n'
|
userChangedStr = "connection " <> sShow pccConnId <> " changed from user " <> plain n <> " to user " <> plain n'
|
||||||
|
|
|
@ -1827,7 +1827,7 @@ testChangePCCUser = testChat2 aliceProfile bobProfile $
|
||||||
\alice bob -> do
|
\alice bob -> do
|
||||||
-- Create a new invite
|
-- Create a new invite
|
||||||
alice ##> "/connect"
|
alice ##> "/connect"
|
||||||
inv <- getInvitation alice
|
_ <- getInvitation alice
|
||||||
-- Create new user and go back to original user
|
-- Create new user and go back to original user
|
||||||
alice ##> "/create user alisa"
|
alice ##> "/create user alisa"
|
||||||
showActiveUser alice "alisa"
|
showActiveUser alice "alisa"
|
||||||
|
@ -1837,12 +1837,18 @@ testChangePCCUser = testChat2 aliceProfile bobProfile $
|
||||||
showActiveUser alice "alice (Alice)"
|
showActiveUser alice "alice (Alice)"
|
||||||
-- Change connection to newly created user
|
-- Change connection to newly created user
|
||||||
alice ##> "/_set conn user :1 2"
|
alice ##> "/_set conn user :1 2"
|
||||||
alice <## "connection 1 changed from user alice to user alisa"
|
alice <## "connection 1 changed from user alice to user alisa, new link:"
|
||||||
|
alice <## ""
|
||||||
|
_ <- getTermLine alice
|
||||||
|
alice <## ""
|
||||||
alice ##> "/user alisa"
|
alice ##> "/user alisa"
|
||||||
showActiveUser alice "alisa"
|
showActiveUser alice "alisa"
|
||||||
-- Change connection back to other user
|
-- Change connection back to other user
|
||||||
alice ##> "/_set conn user :1 3"
|
alice ##> "/_set conn user :1 3"
|
||||||
alice <## "connection 1 changed from user alisa to user alisa2"
|
alice <## "connection 1 changed from user alisa to user alisa2, new link:"
|
||||||
|
alice <## ""
|
||||||
|
inv <- getTermLine alice
|
||||||
|
alice <## ""
|
||||||
alice ##> "/user alisa2"
|
alice ##> "/user alisa2"
|
||||||
showActiveUser alice "alisa2"
|
showActiveUser alice "alisa2"
|
||||||
-- Connect
|
-- Connect
|
||||||
|
@ -1851,13 +1857,14 @@ testChangePCCUser = testChat2 aliceProfile bobProfile $
|
||||||
concurrently_
|
concurrently_
|
||||||
(alice <## "bob (Bob): contact is connected")
|
(alice <## "bob (Bob): contact is connected")
|
||||||
(bob <## "alisa2: contact is connected")
|
(bob <## "alisa2: contact is connected")
|
||||||
|
alice <##> bob
|
||||||
|
|
||||||
testChangePCCUserFromIncognito :: HasCallStack => TestParams -> IO ()
|
testChangePCCUserFromIncognito :: HasCallStack => TestParams -> IO ()
|
||||||
testChangePCCUserFromIncognito = testChat2 aliceProfile bobProfile $
|
testChangePCCUserFromIncognito = testChat2 aliceProfile bobProfile $
|
||||||
\alice bob -> do
|
\alice bob -> do
|
||||||
-- Create a new invite and set as incognito
|
-- Create a new invite and set as incognito
|
||||||
alice ##> "/connect"
|
alice ##> "/connect"
|
||||||
inv <- getInvitation alice
|
_ <- getInvitation alice
|
||||||
alice ##> "/_set incognito :1 on"
|
alice ##> "/_set incognito :1 on"
|
||||||
alice <## "connection 1 changed to incognito"
|
alice <## "connection 1 changed to incognito"
|
||||||
-- Create new user and go back to original user
|
-- Create new user and go back to original user
|
||||||
|
@ -1867,13 +1874,19 @@ testChangePCCUserFromIncognito = testChat2 aliceProfile bobProfile $
|
||||||
showActiveUser alice "alice (Alice)"
|
showActiveUser alice "alice (Alice)"
|
||||||
-- Change connection to newly created user
|
-- Change connection to newly created user
|
||||||
alice ##> "/_set conn user :1 2"
|
alice ##> "/_set conn user :1 2"
|
||||||
alice <## "connection 1 changed from user alice to user alisa"
|
alice <## "connection 1 changed from user alice to user alisa, new link:"
|
||||||
|
alice <## ""
|
||||||
|
_ <- getTermLine alice
|
||||||
|
alice <## ""
|
||||||
alice `hasContactProfiles` ["alice"]
|
alice `hasContactProfiles` ["alice"]
|
||||||
alice ##> "/user alisa"
|
alice ##> "/user alisa"
|
||||||
showActiveUser alice "alisa"
|
showActiveUser alice "alisa"
|
||||||
-- Change connection back to initial user
|
-- Change connection back to initial user
|
||||||
alice ##> "/_set conn user :1 1"
|
alice ##> "/_set conn user :1 1"
|
||||||
alice <## "connection 1 changed from user alisa to user alice"
|
alice <## "connection 1 changed from user alisa to user alice, new link:"
|
||||||
|
alice <## ""
|
||||||
|
inv <- getTermLine alice
|
||||||
|
alice <## ""
|
||||||
alice ##> "/user alice"
|
alice ##> "/user alice"
|
||||||
showActiveUser alice "alice (Alice)"
|
showActiveUser alice "alice (Alice)"
|
||||||
-- Connect
|
-- Connect
|
||||||
|
@ -1882,13 +1895,14 @@ testChangePCCUserFromIncognito = testChat2 aliceProfile bobProfile $
|
||||||
concurrently_
|
concurrently_
|
||||||
(alice <## "bob (Bob): contact is connected")
|
(alice <## "bob (Bob): contact is connected")
|
||||||
(bob <## "alice (Alice): contact is connected")
|
(bob <## "alice (Alice): contact is connected")
|
||||||
|
alice <##> bob
|
||||||
|
|
||||||
testChangePCCUserAndThenIncognito :: HasCallStack => TestParams -> IO ()
|
testChangePCCUserAndThenIncognito :: HasCallStack => TestParams -> IO ()
|
||||||
testChangePCCUserAndThenIncognito = testChat2 aliceProfile bobProfile $
|
testChangePCCUserAndThenIncognito = testChat2 aliceProfile bobProfile $
|
||||||
\alice bob -> do
|
\alice bob -> do
|
||||||
-- Create a new invite and set as incognito
|
-- Create a new invite and set as incognito
|
||||||
alice ##> "/connect"
|
alice ##> "/connect"
|
||||||
inv <- getInvitation alice
|
_ <- getInvitation alice
|
||||||
-- Create new user and go back to original user
|
-- Create new user and go back to original user
|
||||||
alice ##> "/create user alisa"
|
alice ##> "/create user alisa"
|
||||||
showActiveUser alice "alisa"
|
showActiveUser alice "alisa"
|
||||||
|
@ -1896,7 +1910,10 @@ testChangePCCUserAndThenIncognito = testChat2 aliceProfile bobProfile $
|
||||||
showActiveUser alice "alice (Alice)"
|
showActiveUser alice "alice (Alice)"
|
||||||
-- Change connection to newly created user
|
-- Change connection to newly created user
|
||||||
alice ##> "/_set conn user :1 2"
|
alice ##> "/_set conn user :1 2"
|
||||||
alice <## "connection 1 changed from user alice to user alisa"
|
alice <## "connection 1 changed from user alice to user alisa, new link:"
|
||||||
|
alice <## ""
|
||||||
|
inv <- getTermLine alice
|
||||||
|
alice <## ""
|
||||||
alice ##> "/user alisa"
|
alice ##> "/user alisa"
|
||||||
showActiveUser alice "alisa"
|
showActiveUser alice "alisa"
|
||||||
-- Change connection to incognito and make sure it's attached to the newly created user profile
|
-- Change connection to incognito and make sure it's attached to the newly created user profile
|
||||||
|
@ -1911,6 +1928,10 @@ testChangePCCUserAndThenIncognito = testChat2 aliceProfile bobProfile $
|
||||||
alice <## ("bob (Bob): contact is connected, your incognito profile for this contact is " <> alisaIncognito)
|
alice <## ("bob (Bob): contact is connected, your incognito profile for this contact is " <> alisaIncognito)
|
||||||
alice <## ("use /i bob to print out this incognito profile again")
|
alice <## ("use /i bob to print out this incognito profile again")
|
||||||
]
|
]
|
||||||
|
alice ?#> "@bob hi"
|
||||||
|
bob <# (alisaIncognito <> "> hi")
|
||||||
|
bob #> ("@" <> alisaIncognito <> " hey")
|
||||||
|
alice ?<# "bob> hey"
|
||||||
|
|
||||||
testChangePCCUserDiffSrv :: HasCallStack => TestParams -> IO ()
|
testChangePCCUserDiffSrv :: HasCallStack => TestParams -> IO ()
|
||||||
testChangePCCUserDiffSrv ps = do
|
testChangePCCUserDiffSrv ps = do
|
||||||
|
@ -1951,6 +1972,7 @@ testChangePCCUserDiffSrv ps = do
|
||||||
concurrently_
|
concurrently_
|
||||||
(alice <## "bob (Bob): contact is connected")
|
(alice <## "bob (Bob): contact is connected")
|
||||||
(bob <## "alisa: contact is connected")
|
(bob <## "alisa: contact is connected")
|
||||||
|
alice <##> bob
|
||||||
where
|
where
|
||||||
serverCfg' =
|
serverCfg' =
|
||||||
smpServerCfg
|
smpServerCfg
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue