Merge branch 'master' into short-links

This commit is contained in:
spaced4ndy
2025-06-17 10:57:11 +04:00
7 changed files with 80 additions and 67 deletions
+3 -19
View File
@@ -1708,33 +1708,17 @@ processChatCommand' vr = \case
conn <- withFastStore $ \db -> getPendingContactConnection db userId connId
let PendingContactConnection {pccConnStatus, connLinkInv} = conn
case (pccConnStatus, connLinkInv) of
(ConnNew, Just (CCLink cReqInv _)) -> do
(ConnNew, Just _ссLink) -> do
newUser <- privateGetUser newUserId
conn' <- ifM (canKeepLink cReqInv newUser) (updateConn 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
updateConn user@User {userId} conn@PendingContactConnection {customUserProfileId} newUser = do
withAgent $ \a -> changeConnectionUser a (aUserId user) (aConnId' conn) (aUserId newUser)
sLnk <- updatePCCShortLinkData conn $ userProfileToSend newUser Nothing Nothing False
withFastStore' $ \db -> do
conn' <- updatePCCUser db userId conn newUserId sLnk
forM_ customUserProfileId $ \profileId ->
deletePCCIncognitoProfile db user profileId
pure conn'
recreateConn user conn@PendingContactConnection {customUserProfileId, connLinkInv} newUser = do
subMode <- chatReadVar subscriptionMode
let short = isJust $ connShortLink =<< connLinkInv
userData
| short = Just $ shortLinkUserData $ userProfileToSend user Nothing Nothing False
| short = Just $ shortLinkUserData $ userProfileToSend newUser Nothing Nothing False
| otherwise = Nothing
-- TODO [certs rcv]
(agConnId, (ccLink, _serviceId)) <- withAgent $ \a -> createConnection a (aUserId newUser) True SCMInvitation userData Nothing IKPQOn subMode
-18
View File
@@ -71,7 +71,6 @@ module Simplex.Chat.Store.Direct
updateContactAccepted,
getUserByContactRequestId,
getPendingContactConnections,
updatePCCUser,
getContactConnections,
getConnectionById,
getConnectionsContacts,
@@ -519,23 +518,6 @@ updatePCCIncognito db User {userId} conn@PendingContactConnection {connLinkInv}
Just (CCLink cReq _) -> Just (CCLink cReq sLnk)
Nothing -> Nothing
updatePCCUser :: DB.Connection -> UserId -> PendingContactConnection -> UserId -> Maybe ShortLinkInvitation -> IO PendingContactConnection
updatePCCUser db userId conn@PendingContactConnection {connLinkInv} newUserId sLnk = do
updatedAt <- getCurrentTime
DB.execute
db
[sql|
UPDATE connections
SET user_id = ?, short_link_inv = ?, custom_user_profile_id = NULL, updated_at = ?
WHERE user_id = ? AND connection_id = ?
|]
(newUserId, sLnk, updatedAt, userId, pccConnId conn)
pure (conn :: PendingContactConnection) {customUserProfileId = Nothing, connLinkInv = connLinkInv', updatedAt}
where
connLinkInv' = case connLinkInv of
Just (CCLink cReq _) -> Just (CCLink cReq sLnk)
Nothing -> Nothing
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=?)
@@ -4400,14 +4400,6 @@ Query:
Plan:
SEARCH connections USING INTEGER PRIMARY KEY (rowid=?)
Query:
UPDATE connections
SET user_id = ?, short_link_inv = ?, 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 = ?
+10 -5
View File
@@ -1817,10 +1817,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'
@@ -1829,7 +1828,13 @@ viewConnectionUserChanged User {localDisplayName = n} PendingContactConnection {
plain $ maybe cReqStr strEncode shortLink,
""
]
<> ["The invitation link for old clients: " <> plain cReqStr | isJust shortLink]
<>
if isJust shortLink
then
[ "The invitation link for old clients:",
plain cReqStr
]
else []
where
cReqStr = strEncode $ simplexChatInvitation cReq