mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 20:29:53 +00:00
Merge branch 'stable'
This commit is contained in:
commit
8f9bb4dc5b
6 changed files with 34 additions and 54 deletions
|
@ -1696,25 +1696,10 @@ processChatCommand' vr = \case
|
|||
case (pccConnStatus, connLinkInv) of
|
||||
(ConnNew, Just (CCLink cReqInv _)) -> do
|
||||
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
|
||||
_ -> throwChatError CEConnectionUserChangeProhibited
|
||||
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
|
||||
subMode <- chatReadVar subscriptionMode
|
||||
let userData = shortLinkUserData $ isJust $ connShortLink =<< connLinkInv
|
||||
|
|
|
@ -66,7 +66,6 @@ module Simplex.Chat.Store.Direct
|
|||
updateContactAccepted,
|
||||
getUserByContactRequestId,
|
||||
getPendingContactConnections,
|
||||
updatePCCUser,
|
||||
getContactConnections,
|
||||
getConnectionById,
|
||||
getConnectionsContacts,
|
||||
|
@ -440,19 +439,6 @@ updatePCCIncognito db User {userId} conn customUserProfileId = do
|
|||
(customUserProfileId, updatedAt, userId, pccConnId conn)
|
||||
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 User {userId} profileId =
|
||||
DB.execute
|
||||
|
|
|
@ -1071,10 +1071,6 @@ Query: UPDATE connections SET smp_agent_version = ? WHERE conn_id = ?
|
|||
Plan:
|
||||
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 = ?
|
||||
Plan:
|
||||
SEARCH messages USING PRIMARY KEY (conn_id=? AND internal_id=?)
|
||||
|
|
|
@ -4298,14 +4298,6 @@ Query:
|
|||
Plan:
|
||||
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:
|
||||
UPDATE contact_profiles
|
||||
SET contact_link = ?, updated_at = ?
|
||||
|
|
|
@ -1799,10 +1799,9 @@ viewConnectionIncognitoUpdated PendingContactConnection {pccConnId, customUserPr
|
|||
| otherwise = ["connection " <> sShow pccConnId <> " changed to non incognito"]
|
||||
|
||||
viewConnectionUserChanged :: User -> PendingContactConnection -> User -> PendingContactConnection -> [StyledString]
|
||||
viewConnectionUserChanged User {localDisplayName = n} PendingContactConnection {pccConnId, connLinkInv} User {localDisplayName = n'} PendingContactConnection {connLinkInv = connLinkInv'} =
|
||||
case (connLinkInv, connLinkInv') of
|
||||
(Just ccLink, Just ccLink')
|
||||
| ccLink /= ccLink' -> [userChangedStr <> ", new link:"] <> newLink ccLink'
|
||||
viewConnectionUserChanged User {localDisplayName = n} PendingContactConnection {pccConnId} User {localDisplayName = n'} PendingContactConnection {connLinkInv = connLinkInv'} =
|
||||
case connLinkInv' of
|
||||
Just ccLink' -> [userChangedStr <> ", new link:"] <> newLink ccLink'
|
||||
_ -> [userChangedStr]
|
||||
where
|
||||
userChangedStr = "connection " <> sShow pccConnId <> " changed from user " <> plain n <> " to user " <> plain n'
|
||||
|
|
|
@ -1827,7 +1827,7 @@ testChangePCCUser = testChat2 aliceProfile bobProfile $
|
|||
\alice bob -> do
|
||||
-- Create a new invite
|
||||
alice ##> "/connect"
|
||||
inv <- getInvitation alice
|
||||
_ <- getInvitation alice
|
||||
-- Create new user and go back to original user
|
||||
alice ##> "/create user alisa"
|
||||
showActiveUser alice "alisa"
|
||||
|
@ -1837,12 +1837,18 @@ testChangePCCUser = testChat2 aliceProfile bobProfile $
|
|||
showActiveUser alice "alice (Alice)"
|
||||
-- Change connection to newly created user
|
||||
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"
|
||||
showActiveUser alice "alisa"
|
||||
-- Change connection back to other user
|
||||
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"
|
||||
showActiveUser alice "alisa2"
|
||||
-- Connect
|
||||
|
@ -1851,13 +1857,14 @@ testChangePCCUser = testChat2 aliceProfile bobProfile $
|
|||
concurrently_
|
||||
(alice <## "bob (Bob): contact is connected")
|
||||
(bob <## "alisa2: contact is connected")
|
||||
alice <##> bob
|
||||
|
||||
testChangePCCUserFromIncognito :: HasCallStack => TestParams -> IO ()
|
||||
testChangePCCUserFromIncognito = testChat2 aliceProfile bobProfile $
|
||||
\alice bob -> do
|
||||
-- Create a new invite and set as incognito
|
||||
alice ##> "/connect"
|
||||
inv <- getInvitation alice
|
||||
_ <- getInvitation alice
|
||||
alice ##> "/_set incognito :1 on"
|
||||
alice <## "connection 1 changed to incognito"
|
||||
-- Create new user and go back to original user
|
||||
|
@ -1867,13 +1874,19 @@ testChangePCCUserFromIncognito = testChat2 aliceProfile bobProfile $
|
|||
showActiveUser alice "alice (Alice)"
|
||||
-- Change connection to newly created user
|
||||
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 ##> "/user alisa"
|
||||
showActiveUser alice "alisa"
|
||||
-- Change connection back to initial user
|
||||
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"
|
||||
showActiveUser alice "alice (Alice)"
|
||||
-- Connect
|
||||
|
@ -1882,13 +1895,14 @@ testChangePCCUserFromIncognito = testChat2 aliceProfile bobProfile $
|
|||
concurrently_
|
||||
(alice <## "bob (Bob): contact is connected")
|
||||
(bob <## "alice (Alice): contact is connected")
|
||||
alice <##> bob
|
||||
|
||||
testChangePCCUserAndThenIncognito :: HasCallStack => TestParams -> IO ()
|
||||
testChangePCCUserAndThenIncognito = testChat2 aliceProfile bobProfile $
|
||||
\alice bob -> do
|
||||
-- Create a new invite and set as incognito
|
||||
alice ##> "/connect"
|
||||
inv <- getInvitation alice
|
||||
_ <- getInvitation alice
|
||||
-- Create new user and go back to original user
|
||||
alice ##> "/create user alisa"
|
||||
showActiveUser alice "alisa"
|
||||
|
@ -1896,7 +1910,10 @@ testChangePCCUserAndThenIncognito = testChat2 aliceProfile bobProfile $
|
|||
showActiveUser alice "alice (Alice)"
|
||||
-- Change connection to newly created user
|
||||
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"
|
||||
showActiveUser alice "alisa"
|
||||
-- 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 <## ("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 ps = do
|
||||
|
@ -1951,6 +1972,7 @@ testChangePCCUserDiffSrv ps = do
|
|||
concurrently_
|
||||
(alice <## "bob (Bob): contact is connected")
|
||||
(bob <## "alisa: contact is connected")
|
||||
alice <##> bob
|
||||
where
|
||||
serverCfg' =
|
||||
smpServerCfg
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue