diff --git a/Signal/src/contact/OWSContactsManager.h b/Signal/src/contact/OWSContactsManager.h index 2e829309d..bdd8487d7 100644 --- a/Signal/src/contact/OWSContactsManager.h +++ b/Signal/src/contact/OWSContactsManager.h @@ -55,7 +55,7 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification; // This variant will fetch system contacts if contact access has already been granted, // but not prompt for contact access. Also, it will always notify delegates, even if -// contacts haven't changed, and will clear out any stale cached SignalAccount's +// contacts haven't changed, and will clear out any stale cached SignalAccounts - (void)userRequestedSystemContactsRefreshWithCompletion:(void (^)(NSError *_Nullable error))completionHandler; #pragma mark - Util diff --git a/Signal/src/contact/OWSContactsManager.m b/Signal/src/contact/OWSContactsManager.m index 20f811c02..90c351a68 100644 --- a/Signal/src/contact/OWSContactsManager.m +++ b/Signal/src/contact/OWSContactsManager.m @@ -131,9 +131,9 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification - (void)systemContactsFetcher:(SystemContactsFetcher *)systemsContactsFetcher updatedContacts:(NSArray *)contacts - userRequested:(BOOL)userRequested + isUserRequested:(BOOL)isUserRequested { - [self updateWithContacts:contacts clearStaleCache:userRequested]; + [self updateWithContacts:contacts shouldClearStaleCache:isUserRequested]; } #pragma mark - Intersection @@ -191,7 +191,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification [self.avatarCache removeAllImagesForKey:recipientId]; } -- (void)updateWithContacts:(NSArray *)contacts clearStaleCache:(BOOL)clearStaleCache +- (void)updateWithContacts:(NSArray *)contacts shouldClearStaleCache:(BOOL)shouldClearStaleCache { dispatch_async(self.serialQueue, ^{ NSMutableDictionary *allContactsMap = [NSMutableDictionary new]; @@ -211,13 +211,13 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification [self.avatarCache removeAllImages]; [self intersectContactsWithCompletion:^(NSError *_Nullable error) { - [self buildSignalAccountsAndClearStaleCache:clearStaleCache]; + [self buildSignalAccountsAndClearStaleCache:shouldClearStaleCache]; }]; }); }); } -- (void)buildSignalAccountsAndClearStaleCache:(BOOL)clearStaleCache; +- (void)buildSignalAccountsAndClearStaleCache:(BOOL)shouldClearStaleCache; { dispatch_async(self.serialQueue, ^{ NSMutableArray *signalAccounts = [NSMutableArray new]; @@ -259,12 +259,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification [SignalAccount enumerateCollectionObjectsWithTransaction:transaction usingBlock:^(id _Nonnull object, BOOL *_Nonnull stop) { - if (![object isKindOfClass:[SignalAccount class]]) { - OWSFail(@"%@ Unexpected object in signal account collection: %@", - self.logTag, - object); - return; - } + OWSAssert([object isKindOfClass:[SignalAccount class]]); SignalAccount *oldSignalAccount = (SignalAccount *)object; oldSignalAccounts[oldSignalAccount.uniqueId] = oldSignalAccount; @@ -301,7 +296,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification [signalAccount saveWithTransaction:transaction]; } - if (clearStaleCache) { + if (shouldClearStaleCache) { DDLogInfo(@"%@ Removing %lu old SignalAccounts.", self.logTag, (unsigned long)oldSignalAccounts.count); for (SignalAccount *signalAccount in oldSignalAccounts.allValues) { DDLogVerbose(@"%@ Removing old SignalAccount: %@", self.logTag, signalAccount); diff --git a/Signal/src/contact/SystemContactsFetcher.swift b/Signal/src/contact/SystemContactsFetcher.swift index 41baba6b8..a70d8b838 100644 --- a/Signal/src/contact/SystemContactsFetcher.swift +++ b/Signal/src/contact/SystemContactsFetcher.swift @@ -316,7 +316,7 @@ class ContactStoreAdapter: ContactStoreAdaptee { } @objc protocol SystemContactsFetcherDelegate: class { - func systemContactsFetcher(_ systemContactsFetcher: SystemContactsFetcher, updatedContacts contacts: [Contact], userRequested: Bool) + func systemContactsFetcher(_ systemContactsFetcher: SystemContactsFetcher, updatedContacts contacts: [Contact], isUserRequested: Bool) } @objc @@ -361,7 +361,7 @@ class SystemContactsFetcher: NSObject { hasSetupObservation = true self.contactStoreAdapter.startObservingChanges { [weak self] in DispatchQueue.main.async { - self?.updateContacts(completion: nil, userRequested: false) + self?.updateContacts(completion: nil, isUserRequested: false) } } } @@ -431,7 +431,7 @@ class SystemContactsFetcher: NSObject { return } - updateContacts(completion: nil, userRequested: false) + updateContacts(completion: nil, isUserRequested: false) } public func userRequestedRefresh(completion: @escaping (Error?) -> Void) { @@ -441,10 +441,10 @@ class SystemContactsFetcher: NSObject { return } - updateContacts(completion: completion, userRequested: true) + updateContacts(completion: completion, isUserRequested: true) } - private func updateContacts(completion completionParam: ((Error?) -> Void)?, userRequested: Bool = false) { + private func updateContacts(completion completionParam: ((Error?) -> Void)?, isUserRequested: Bool = false) { AssertIsOnMainThread() // Ensure completion is invoked on main thread. @@ -484,7 +484,7 @@ class SystemContactsFetcher: NSObject { if self.lastContactUpdateHash != contactsHash { Logger.info("\(self.TAG) contact hash changed. new contactsHash: \(contactsHash)") shouldNotifyDelegate = true - } else if userRequested { + } else if isUserRequested { Logger.info("\(self.TAG) ignoring debounce due to user request") shouldNotifyDelegate = true } else { @@ -517,7 +517,7 @@ class SystemContactsFetcher: NSObject { self.lastDelegateNotificationDate = Date() self.lastContactUpdateHash = contactsHash - self.delegate?.systemContactsFetcher(self, updatedContacts: contacts, userRequested: userRequested) + self.delegate?.systemContactsFetcher(self, updatedContacts: contacts, isUserRequested: isUserRequested) completion(nil) } }