core: reset address and preferences when updating profile of member without associated contact (#3701)

This commit is contained in:
spaced4ndy
2024-01-18 20:07:43 +04:00
committed by GitHub
parent b5fe1f8364
commit ddcd7d495e
2 changed files with 22 additions and 3 deletions

View File

@@ -12,6 +12,8 @@ module Simplex.Chat.Store.Direct
( updateContactLDN_,
updateContactProfile_,
updateContactProfile_',
updateMemberContactProfileReset_',
updateMemberContactProfileReset_,
updateMemberContactProfile_,
updateMemberContactProfile_',
deleteContactProfile_,
@@ -455,7 +457,24 @@ updateContactProfile_' db userId profileId Profile {displayName, fullName, image
|]
(displayName, fullName, image, contactLink, preferences, updatedAt, userId, profileId)
-- update only member profile fields
-- update only member profile fields (when member doesn't have associated contact - we can reset contactLink and prefs)
updateMemberContactProfileReset_ :: DB.Connection -> UserId -> ProfileId -> Profile -> IO ()
updateMemberContactProfileReset_ db userId profileId profile = do
currentTs <- getCurrentTime
updateMemberContactProfileReset_' db userId profileId profile currentTs
updateMemberContactProfileReset_' :: DB.Connection -> UserId -> ProfileId -> Profile -> UTCTime -> IO ()
updateMemberContactProfileReset_' db userId profileId Profile {displayName, fullName, image} updatedAt = do
DB.execute
db
[sql|
UPDATE contact_profiles
SET display_name = ?, full_name = ?, image = ?, contact_link = NULL, preferences = NULL, updated_at = ?
WHERE user_id = ? AND contact_profile_id = ?
|]
(displayName, fullName, image, updatedAt, userId, profileId)
-- update only member profile fields (when member has associated contact - we keep contactLink and prefs)
updateMemberContactProfile_ :: DB.Connection -> UserId -> ProfileId -> Profile -> IO ()
updateMemberContactProfile_ db userId profileId profile = do
currentTs <- getCurrentTime

View File

@@ -1990,12 +1990,12 @@ createMemberContactConn_
updateMemberProfile :: DB.Connection -> User -> GroupMember -> Profile -> ExceptT StoreError IO GroupMember
updateMemberProfile db User {userId} m p'
| displayName == newName = do
liftIO $ updateMemberContactProfile_ db userId profileId p'
liftIO $ updateMemberContactProfileReset_ db userId profileId p'
pure m {memberProfile = profile}
| otherwise =
ExceptT . withLocalDisplayName db userId newName $ \ldn -> do
currentTs <- getCurrentTime
updateMemberContactProfile_' db userId profileId p' currentTs
updateMemberContactProfileReset_' db userId profileId p' currentTs
DB.execute
db
"UPDATE group_members SET local_display_name = ?, updated_at = ? WHERE user_id = ? AND group_member_id = ?"