Fix local SignalRecipient if needed
This commit is contained in:
parent
48f2c42c4f
commit
1094d866d3
@ -241,8 +241,8 @@ public class LegacyChangePhoneNumber: NSObject {
|
||||
let recipientMerger = DependenciesBridge.shared.recipientMerger
|
||||
let localRecipient = recipientMerger.applyMergeForLocalAccount(
|
||||
aci: serviceAci,
|
||||
pni: servicePni,
|
||||
phoneNumber: serviceE164,
|
||||
pni: servicePni,
|
||||
tx: transaction.asV2Write
|
||||
)
|
||||
localRecipient.markAsRegisteredAndSave(tx: transaction)
|
||||
|
||||
@ -303,8 +303,8 @@ public extension TSAccountManager {
|
||||
|
||||
let localRecipient = DependenciesBridge.shared.recipientMerger.applyMergeForLocalAccount(
|
||||
aci: newAci.wrappedAciValue,
|
||||
pni: newPni?.wrappedPniValue,
|
||||
phoneNumber: newLocalNumber.wrappedValue,
|
||||
pni: newPni?.wrappedPniValue,
|
||||
tx: transaction.asV2Write
|
||||
)
|
||||
localRecipient.markAsRegisteredAndSave(tx: transaction)
|
||||
|
||||
@ -12,8 +12,8 @@ public protocol RecipientMerger {
|
||||
/// time we're allowed to "merge" the identifiers for our own account.
|
||||
func applyMergeForLocalAccount(
|
||||
aci: Aci,
|
||||
pni: Pni?,
|
||||
phoneNumber: E164,
|
||||
pni: Pni?,
|
||||
tx: DBWriteTransaction
|
||||
) -> SignalRecipient
|
||||
|
||||
@ -160,8 +160,8 @@ class RecipientMergerImpl: RecipientMerger {
|
||||
|
||||
func applyMergeForLocalAccount(
|
||||
aci: Aci,
|
||||
pni: Pni?,
|
||||
phoneNumber: E164,
|
||||
pni: Pni?,
|
||||
tx: DBWriteTransaction
|
||||
) -> SignalRecipient {
|
||||
return mergeAlways(aci: aci, phoneNumber: phoneNumber, isLocalRecipient: true, tx: tx)
|
||||
|
||||
@ -493,19 +493,6 @@ public class SignalServiceAddressCache: NSObject {
|
||||
owsAssertDebug(GRDBSchemaMigrator.areMigrationsComplete)
|
||||
|
||||
databaseStorage.read { transaction in
|
||||
if let localIdentifiers = tsAccountManager.localIdentifiers(transaction: transaction) {
|
||||
updateRecipient(
|
||||
aci: localIdentifiers.aci,
|
||||
// PNI TODO: Fetch our own PNI once it's stored on our SignalRecipient.
|
||||
//
|
||||
// (Even though our own PNI may be available at this point, we should have
|
||||
// a recipient for ourselves, so we'd immediately overwrite it during the
|
||||
// `anyEnumerate` below.)
|
||||
pni: nil,
|
||||
phoneNumber: localIdentifiers.phoneNumber
|
||||
)
|
||||
}
|
||||
|
||||
SignalRecipient.anyEnumerate(transaction: transaction) { recipient, _ in
|
||||
self.updateRecipient(recipient)
|
||||
}
|
||||
|
||||
@ -229,6 +229,7 @@ public class SSKEnvironment: NSObject {
|
||||
}
|
||||
warmCachesForObject("signalProxy", SignalProxy.warmCaches)
|
||||
warmCachesForObject("tsAccountManager", tsAccountManager.warmCaches)
|
||||
warmCachesForObject("fixLocalRecipient", fixLocalRecipientIfNeeded)
|
||||
warmCachesForObject("signalServiceAddressCache", signalServiceAddressCache.warmCaches)
|
||||
warmCachesForObject("signalService", signalService.warmCaches)
|
||||
warmCachesForObject("remoteConfigManager", remoteConfigManager.warmCaches)
|
||||
@ -251,6 +252,29 @@ public class SSKEnvironment: NSObject {
|
||||
NotificationCenter.default.post(name: SSKEnvironment.warmCachesNotification, object: nil)
|
||||
}
|
||||
|
||||
/// Ensures the local SignalRecipient is correct.
|
||||
///
|
||||
/// This primarily serves to ensure the local SignalRecipient has its own
|
||||
/// Pni (a one-time migration), but it also helps ensure that the value is
|
||||
/// always consistent with TSAccountManager's values.
|
||||
private func fixLocalRecipientIfNeeded() {
|
||||
databaseStorage.write { tx in
|
||||
guard let localIdentifiers = tsAccountManager.localIdentifiers(transaction: tx) else {
|
||||
return // Not registered yet.
|
||||
}
|
||||
guard let phoneNumber = E164(localIdentifiers.phoneNumber) else {
|
||||
return // Registered with an invalid phone number.
|
||||
}
|
||||
let recipientMerger = DependenciesBridge.shared.recipientMerger
|
||||
_ = recipientMerger.applyMergeForLocalAccount(
|
||||
aci: localIdentifiers.aci,
|
||||
phoneNumber: phoneNumber,
|
||||
pni: localIdentifiers.pni,
|
||||
tx: tx.asV2Write
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#if TESTABLE_BUILD
|
||||
|
||||
public func setContactsManagerForUnitTests(_ contactsManager: ContactsManagerProtocol) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user