mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 12:19:54 +00:00
fix deduplication, fix address deletion
This commit is contained in:
parent
bdcb480a4a
commit
2f143b5bf2
3 changed files with 9 additions and 38 deletions
|
@ -200,6 +200,7 @@ createOrUpdateContactRequest
|
|||
createBusinessChat = do
|
||||
let Profile {preferences = userPreferences} = profileToSendOnAccept user Nothing True
|
||||
groupPreferences = maybe defaultBusinessGroupPrefs businessGroupPrefs userPreferences
|
||||
-- TODO pass profileId, ldn? profileId for member, ldn for group?
|
||||
(gInfo@GroupInfo {groupId}, clientMember) <-
|
||||
createBusinessRequestGroup db vr gVar user cReqChatVRange profile groupPreferences
|
||||
liftIO $
|
||||
|
@ -210,12 +211,13 @@ createOrUpdateContactRequest
|
|||
ucr <- getContactRequest db user contactRequestId
|
||||
pure $ RSCurrentRequest ucr (Just $ REBusinessChat gInfo clientMember) False
|
||||
updateContactRequest :: UserContactRequest -> ExceptT StoreError IO RequestStage
|
||||
updateContactRequest ucr@UserContactRequest {contactRequestId = cReqId, contactId_, localDisplayName = oldLdn, profile = Profile {displayName = oldDisplayName}} = do
|
||||
updateContactRequest ucr@UserContactRequest {contactRequestId, contactId_, localDisplayName = oldLdn, profile = Profile {displayName = oldDisplayName}} = do
|
||||
currentTs <- liftIO getCurrentTime
|
||||
liftIO $ updateProfile currentTs
|
||||
updateRequest currentTs
|
||||
re_ <- getRequestEntity ucr
|
||||
pure $ RSCurrentRequest ucr re_ True
|
||||
ucr' <- getContactRequest db user contactRequestId
|
||||
re_ <- getRequestEntity ucr'
|
||||
pure $ RSCurrentRequest ucr' re_ True
|
||||
where
|
||||
updateProfile currentTs =
|
||||
DB.execute
|
||||
|
@ -234,7 +236,7 @@ createOrUpdateContactRequest
|
|||
AND contact_request_id = ?
|
||||
)
|
||||
|]
|
||||
(displayName, fullName, image, contactLink, currentTs, userId, cReqId)
|
||||
(displayName, fullName, image, contactLink, currentTs, userId, contactRequestId)
|
||||
updateRequest currentTs =
|
||||
if displayName == oldDisplayName
|
||||
then
|
||||
|
@ -246,7 +248,7 @@ createOrUpdateContactRequest
|
|||
SET agent_invitation_id = ?, pq_support = ?, peer_chat_min_version = ?, peer_chat_max_version = ?, updated_at = ?
|
||||
WHERE user_id = ? AND contact_request_id = ?
|
||||
|]
|
||||
(Binary invId, pqSup, minV, maxV, currentTs, userId, cReqId)
|
||||
(Binary invId, pqSup, minV, maxV, currentTs, userId, contactRequestId)
|
||||
else
|
||||
ExceptT $ withLocalDisplayName db userId displayName $ \ldn -> runExceptT $ do
|
||||
liftIO $ do
|
||||
|
@ -257,8 +259,8 @@ createOrUpdateContactRequest
|
|||
SET agent_invitation_id = ?, pq_support = ?, peer_chat_min_version = ?, peer_chat_max_version = ?, local_display_name = ?, updated_at = ?
|
||||
WHERE user_id = ? AND contact_request_id = ?
|
||||
|]
|
||||
(Binary invId, pqSup, minV, maxV, ldn, currentTs, userId, cReqId)
|
||||
-- TODO update business chat?
|
||||
(Binary invId, pqSup, minV, maxV, ldn, currentTs, userId, contactRequestId)
|
||||
-- TODO update business chat? member ldn, group ldn and profile?
|
||||
-- Here we could also update business chat, but is always synchronously auto-accepted so it's less of an issue
|
||||
forM_ contactId_ $ \contactId ->
|
||||
DB.execute
|
||||
|
|
|
@ -64,7 +64,6 @@ module Simplex.Chat.Store.Direct
|
|||
createContactFromRequest,
|
||||
createAcceptedContactConn,
|
||||
createAcceptedContact,
|
||||
deleteContactRequestRec,
|
||||
updateContactAccepted,
|
||||
getUserByContactRequestId,
|
||||
getPendingContactConnections,
|
||||
|
@ -809,10 +808,6 @@ createAcceptedContact
|
|||
ct <- getContact db vr user contactId
|
||||
pure (ct, conn)
|
||||
|
||||
deleteContactRequestRec :: DB.Connection -> User -> UserContactRequest -> IO ()
|
||||
deleteContactRequestRec db User {userId} UserContactRequest {contactRequestId} =
|
||||
DB.execute db "DELETE FROM contact_requests WHERE user_id = ? AND contact_request_id = ?" (userId, contactRequestId)
|
||||
|
||||
updateContactAccepted :: DB.Connection -> User -> Contact -> Bool -> IO ()
|
||||
updateContactAccepted db User {userId} Contact {contactId} contactUsed =
|
||||
DB.execute
|
||||
|
|
|
@ -413,32 +413,6 @@ deleteUserAddress db user@User {userId} = do
|
|||
)
|
||||
|]
|
||||
(Only userId)
|
||||
DB.execute
|
||||
db
|
||||
[sql|
|
||||
DELETE FROM display_names
|
||||
WHERE user_id = ?
|
||||
AND local_display_name in (
|
||||
SELECT cr.local_display_name
|
||||
FROM contact_requests cr
|
||||
JOIN user_contact_links uc USING (user_contact_link_id)
|
||||
WHERE uc.user_id = ? AND uc.local_display_name = '' AND uc.group_id IS NULL
|
||||
)
|
||||
AND local_display_name NOT IN (SELECT local_display_name FROM users WHERE user_id = ?)
|
||||
|]
|
||||
(userId, userId, userId)
|
||||
DB.execute
|
||||
db
|
||||
[sql|
|
||||
DELETE FROM contact_profiles
|
||||
WHERE contact_profile_id in (
|
||||
SELECT cr.contact_profile_id
|
||||
FROM contact_requests cr
|
||||
JOIN user_contact_links uc USING (user_contact_link_id)
|
||||
WHERE uc.user_id = ? AND uc.local_display_name = '' AND uc.group_id IS NULL
|
||||
)
|
||||
|]
|
||||
(Only userId)
|
||||
void $ setUserProfileContactLink db user Nothing
|
||||
DB.execute db "DELETE FROM user_contact_links WHERE user_id = ? AND local_display_name = '' AND group_id IS NULL" (Only userId)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue