From 037da84de1295dbb3f15db509efed55a2ad7a87b Mon Sep 17 00:00:00 2001 From: Max Radermacher Date: Wed, 5 Apr 2023 11:54:07 -0700 Subject: [PATCH] Fix change number obsolete profile handling --- .../src/Contacts/SignalRecipient.swift | 15 +++++++++-- .../src/Util/Profiles/ProfileFetcherJob.swift | 27 ------------------- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/SignalServiceKit/src/Contacts/SignalRecipient.swift b/SignalServiceKit/src/Contacts/SignalRecipient.swift index 0551908ae5..ee310f7081 100644 --- a/SignalServiceKit/src/Contacts/SignalRecipient.swift +++ b/SignalServiceKit/src/Contacts/SignalRecipient.swift @@ -153,6 +153,19 @@ extension SignalRecipient { newUuid: newServiceIdString, transaction: transaction.unwrapGrdbWrite) + if let oldPhoneNumber { + // If we have an `oldPhoneNumber`, it means that value is now detached from + // everything. If there is any profile that refers exclusively to that + // phone number, we can delete it. (If there are profiles that refer to + // some other ACI, we should keep those since they're for accounts that are + // potentially still valid.) + let sql = """ + DELETE FROM \(UserProfileRecord.databaseTableName) + WHERE \(userProfileColumn: .recipientPhoneNumber) = ? AND \(userProfileColumn: .recipientUUID) IS NULL + """ + transaction.unwrapGrdbWrite.execute(sql: sql, arguments: [oldPhoneNumber]) + } + if let newServiceId, let localAci = tsAccountManager.localUuid(with: transaction).map({ ServiceId($0) }), localAci != newServiceId, @@ -247,8 +260,6 @@ extension SignalRecipient { } if let obsoleteAddress { - ProfileFetcherJob.clearProfileState(address: obsoleteAddress, transaction: transaction) - transaction.addAsyncCompletion(queue: .global()) { Self.udManager.setUnidentifiedAccessMode(.unknown, address: obsoleteAddress) } diff --git a/SignalServiceKit/src/Util/Profiles/ProfileFetcherJob.swift b/SignalServiceKit/src/Util/Profiles/ProfileFetcherJob.swift index 11c6309164..f4e6849551 100644 --- a/SignalServiceKit/src/Util/Profiles/ProfileFetcherJob.swift +++ b/SignalServiceKit/src/Util/Profiles/ProfileFetcherJob.swift @@ -571,33 +571,6 @@ public class ProfileFetcherJob: NSObject { } } - public static func clearProfileState(address: SignalServiceAddress, transaction: SDSAnyWriteTransaction) { - - // TODO: We could immediately discard profile state for this address as well. - - self.profileManager.updateProfile( - for: address, - givenName: nil, - familyName: nil, - bio: nil, - bioEmoji: nil, - avatarUrlPath: nil, - optionalAvatarFileUrl: nil, - profileBadges: nil, - lastFetch: Date.distantPast, - isStoriesCapable: false, - canReceiveGiftBadges: false, - isPniCapable: false, - userProfileWriter: .profileFetch, - authedAccount: .implicit(), - transaction: transaction - ) - - self.paymentsHelper.setArePaymentsEnabled(for: address, - hasPaymentsEnabled: false, - transaction: transaction) - } - private static func updateUnidentifiedAccess(address: SignalServiceAddress, verifier: Data?, hasUnrestrictedAccess: Bool) {