mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 20:29:53 +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
|
createBusinessChat = do
|
||||||
let Profile {preferences = userPreferences} = profileToSendOnAccept user Nothing True
|
let Profile {preferences = userPreferences} = profileToSendOnAccept user Nothing True
|
||||||
groupPreferences = maybe defaultBusinessGroupPrefs businessGroupPrefs userPreferences
|
groupPreferences = maybe defaultBusinessGroupPrefs businessGroupPrefs userPreferences
|
||||||
|
-- TODO pass profileId, ldn? profileId for member, ldn for group?
|
||||||
(gInfo@GroupInfo {groupId}, clientMember) <-
|
(gInfo@GroupInfo {groupId}, clientMember) <-
|
||||||
createBusinessRequestGroup db vr gVar user cReqChatVRange profile groupPreferences
|
createBusinessRequestGroup db vr gVar user cReqChatVRange profile groupPreferences
|
||||||
liftIO $
|
liftIO $
|
||||||
|
@ -210,12 +211,13 @@ createOrUpdateContactRequest
|
||||||
ucr <- getContactRequest db user contactRequestId
|
ucr <- getContactRequest db user contactRequestId
|
||||||
pure $ RSCurrentRequest ucr (Just $ REBusinessChat gInfo clientMember) False
|
pure $ RSCurrentRequest ucr (Just $ REBusinessChat gInfo clientMember) False
|
||||||
updateContactRequest :: UserContactRequest -> ExceptT StoreError IO RequestStage
|
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
|
currentTs <- liftIO getCurrentTime
|
||||||
liftIO $ updateProfile currentTs
|
liftIO $ updateProfile currentTs
|
||||||
updateRequest currentTs
|
updateRequest currentTs
|
||||||
re_ <- getRequestEntity ucr
|
ucr' <- getContactRequest db user contactRequestId
|
||||||
pure $ RSCurrentRequest ucr re_ True
|
re_ <- getRequestEntity ucr'
|
||||||
|
pure $ RSCurrentRequest ucr' re_ True
|
||||||
where
|
where
|
||||||
updateProfile currentTs =
|
updateProfile currentTs =
|
||||||
DB.execute
|
DB.execute
|
||||||
|
@ -234,7 +236,7 @@ createOrUpdateContactRequest
|
||||||
AND contact_request_id = ?
|
AND contact_request_id = ?
|
||||||
)
|
)
|
||||||
|]
|
|]
|
||||||
(displayName, fullName, image, contactLink, currentTs, userId, cReqId)
|
(displayName, fullName, image, contactLink, currentTs, userId, contactRequestId)
|
||||||
updateRequest currentTs =
|
updateRequest currentTs =
|
||||||
if displayName == oldDisplayName
|
if displayName == oldDisplayName
|
||||||
then
|
then
|
||||||
|
@ -246,7 +248,7 @@ createOrUpdateContactRequest
|
||||||
SET agent_invitation_id = ?, pq_support = ?, peer_chat_min_version = ?, peer_chat_max_version = ?, updated_at = ?
|
SET agent_invitation_id = ?, pq_support = ?, peer_chat_min_version = ?, peer_chat_max_version = ?, updated_at = ?
|
||||||
WHERE user_id = ? AND contact_request_id = ?
|
WHERE user_id = ? AND contact_request_id = ?
|
||||||
|]
|
|]
|
||||||
(Binary invId, pqSup, minV, maxV, currentTs, userId, cReqId)
|
(Binary invId, pqSup, minV, maxV, currentTs, userId, contactRequestId)
|
||||||
else
|
else
|
||||||
ExceptT $ withLocalDisplayName db userId displayName $ \ldn -> runExceptT $ do
|
ExceptT $ withLocalDisplayName db userId displayName $ \ldn -> runExceptT $ do
|
||||||
liftIO $ 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 = ?
|
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 = ?
|
WHERE user_id = ? AND contact_request_id = ?
|
||||||
|]
|
|]
|
||||||
(Binary invId, pqSup, minV, maxV, ldn, currentTs, userId, cReqId)
|
(Binary invId, pqSup, minV, maxV, ldn, currentTs, userId, contactRequestId)
|
||||||
-- TODO update business chat?
|
-- 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
|
-- Here we could also update business chat, but is always synchronously auto-accepted so it's less of an issue
|
||||||
forM_ contactId_ $ \contactId ->
|
forM_ contactId_ $ \contactId ->
|
||||||
DB.execute
|
DB.execute
|
||||||
|
|
|
@ -64,7 +64,6 @@ module Simplex.Chat.Store.Direct
|
||||||
createContactFromRequest,
|
createContactFromRequest,
|
||||||
createAcceptedContactConn,
|
createAcceptedContactConn,
|
||||||
createAcceptedContact,
|
createAcceptedContact,
|
||||||
deleteContactRequestRec,
|
|
||||||
updateContactAccepted,
|
updateContactAccepted,
|
||||||
getUserByContactRequestId,
|
getUserByContactRequestId,
|
||||||
getPendingContactConnections,
|
getPendingContactConnections,
|
||||||
|
@ -809,10 +808,6 @@ createAcceptedContact
|
||||||
ct <- getContact db vr user contactId
|
ct <- getContact db vr user contactId
|
||||||
pure (ct, conn)
|
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.Connection -> User -> Contact -> Bool -> IO ()
|
||||||
updateContactAccepted db User {userId} Contact {contactId} contactUsed =
|
updateContactAccepted db User {userId} Contact {contactId} contactUsed =
|
||||||
DB.execute
|
DB.execute
|
||||||
|
|
|
@ -413,32 +413,6 @@ deleteUserAddress db user@User {userId} = do
|
||||||
)
|
)
|
||||||
|]
|
|]
|
||||||
(Only userId)
|
(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
|
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)
|
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