CR: clarify names, comments, asserts

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 60eac4e0bf
commit 1955f3664b

@ -55,7 +55,7 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification;
// This variant will fetch system contacts if contact access has already been granted, // 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 // 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; - (void)userRequestedSystemContactsRefreshWithCompletion:(void (^)(NSError *_Nullable error))completionHandler;
#pragma mark - Util #pragma mark - Util

@ -131,9 +131,9 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
- (void)systemContactsFetcher:(SystemContactsFetcher *)systemsContactsFetcher - (void)systemContactsFetcher:(SystemContactsFetcher *)systemsContactsFetcher
updatedContacts:(NSArray<Contact *> *)contacts updatedContacts:(NSArray<Contact *> *)contacts
userRequested:(BOOL)userRequested isUserRequested:(BOOL)isUserRequested
{ {
[self updateWithContacts:contacts clearStaleCache:userRequested]; [self updateWithContacts:contacts shouldClearStaleCache:isUserRequested];
} }
#pragma mark - Intersection #pragma mark - Intersection
@ -191,7 +191,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
[self.avatarCache removeAllImagesForKey:recipientId]; [self.avatarCache removeAllImagesForKey:recipientId];
} }
- (void)updateWithContacts:(NSArray<Contact *> *)contacts clearStaleCache:(BOOL)clearStaleCache - (void)updateWithContacts:(NSArray<Contact *> *)contacts shouldClearStaleCache:(BOOL)shouldClearStaleCache
{ {
dispatch_async(self.serialQueue, ^{ dispatch_async(self.serialQueue, ^{
NSMutableDictionary<NSString *, Contact *> *allContactsMap = [NSMutableDictionary new]; NSMutableDictionary<NSString *, Contact *> *allContactsMap = [NSMutableDictionary new];
@ -211,13 +211,13 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
[self.avatarCache removeAllImages]; [self.avatarCache removeAllImages];
[self intersectContactsWithCompletion:^(NSError *_Nullable error) { [self intersectContactsWithCompletion:^(NSError *_Nullable error) {
[self buildSignalAccountsAndClearStaleCache:clearStaleCache]; [self buildSignalAccountsAndClearStaleCache:shouldClearStaleCache];
}]; }];
}); });
}); });
} }
- (void)buildSignalAccountsAndClearStaleCache:(BOOL)clearStaleCache; - (void)buildSignalAccountsAndClearStaleCache:(BOOL)shouldClearStaleCache;
{ {
dispatch_async(self.serialQueue, ^{ dispatch_async(self.serialQueue, ^{
NSMutableArray<SignalAccount *> *signalAccounts = [NSMutableArray new]; NSMutableArray<SignalAccount *> *signalAccounts = [NSMutableArray new];
@ -259,12 +259,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
[SignalAccount [SignalAccount
enumerateCollectionObjectsWithTransaction:transaction enumerateCollectionObjectsWithTransaction:transaction
usingBlock:^(id _Nonnull object, BOOL *_Nonnull stop) { usingBlock:^(id _Nonnull object, BOOL *_Nonnull stop) {
if (![object isKindOfClass:[SignalAccount class]]) { OWSAssert([object isKindOfClass:[SignalAccount class]]);
OWSFail(@"%@ Unexpected object in signal account collection: %@",
self.logTag,
object);
return;
}
SignalAccount *oldSignalAccount = (SignalAccount *)object; SignalAccount *oldSignalAccount = (SignalAccount *)object;
oldSignalAccounts[oldSignalAccount.uniqueId] = oldSignalAccount; oldSignalAccounts[oldSignalAccount.uniqueId] = oldSignalAccount;
@ -301,7 +296,7 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
[signalAccount saveWithTransaction:transaction]; [signalAccount saveWithTransaction:transaction];
} }
if (clearStaleCache) { if (shouldClearStaleCache) {
DDLogInfo(@"%@ Removing %lu old SignalAccounts.", self.logTag, (unsigned long)oldSignalAccounts.count); DDLogInfo(@"%@ Removing %lu old SignalAccounts.", self.logTag, (unsigned long)oldSignalAccounts.count);
for (SignalAccount *signalAccount in oldSignalAccounts.allValues) { for (SignalAccount *signalAccount in oldSignalAccounts.allValues) {
DDLogVerbose(@"%@ Removing old SignalAccount: %@", self.logTag, signalAccount); DDLogVerbose(@"%@ Removing old SignalAccount: %@", self.logTag, signalAccount);

@ -316,7 +316,7 @@ class ContactStoreAdapter: ContactStoreAdaptee {
} }
@objc protocol SystemContactsFetcherDelegate: class { @objc protocol SystemContactsFetcherDelegate: class {
func systemContactsFetcher(_ systemContactsFetcher: SystemContactsFetcher, updatedContacts contacts: [Contact], userRequested: Bool) func systemContactsFetcher(_ systemContactsFetcher: SystemContactsFetcher, updatedContacts contacts: [Contact], isUserRequested: Bool)
} }
@objc @objc
@ -361,7 +361,7 @@ class SystemContactsFetcher: NSObject {
hasSetupObservation = true hasSetupObservation = true
self.contactStoreAdapter.startObservingChanges { [weak self] in self.contactStoreAdapter.startObservingChanges { [weak self] in
DispatchQueue.main.async { DispatchQueue.main.async {
self?.updateContacts(completion: nil, userRequested: false) self?.updateContacts(completion: nil, isUserRequested: false)
} }
} }
} }
@ -431,7 +431,7 @@ class SystemContactsFetcher: NSObject {
return return
} }
updateContacts(completion: nil, userRequested: false) updateContacts(completion: nil, isUserRequested: false)
} }
public func userRequestedRefresh(completion: @escaping (Error?) -> Void) { public func userRequestedRefresh(completion: @escaping (Error?) -> Void) {
@ -441,10 +441,10 @@ class SystemContactsFetcher: NSObject {
return 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() AssertIsOnMainThread()
// Ensure completion is invoked on main thread. // Ensure completion is invoked on main thread.
@ -484,7 +484,7 @@ class SystemContactsFetcher: NSObject {
if self.lastContactUpdateHash != contactsHash { if self.lastContactUpdateHash != contactsHash {
Logger.info("\(self.TAG) contact hash changed. new contactsHash: \(contactsHash)") Logger.info("\(self.TAG) contact hash changed. new contactsHash: \(contactsHash)")
shouldNotifyDelegate = true shouldNotifyDelegate = true
} else if userRequested { } else if isUserRequested {
Logger.info("\(self.TAG) ignoring debounce due to user request") Logger.info("\(self.TAG) ignoring debounce due to user request")
shouldNotifyDelegate = true shouldNotifyDelegate = true
} else { } else {
@ -517,7 +517,7 @@ class SystemContactsFetcher: NSObject {
self.lastDelegateNotificationDate = Date() self.lastDelegateNotificationDate = Date()
self.lastContactUpdateHash = contactsHash self.lastContactUpdateHash = contactsHash
self.delegate?.systemContactsFetcher(self, updatedContacts: contacts, userRequested: userRequested) self.delegate?.systemContactsFetcher(self, updatedContacts: contacts, isUserRequested: isUserRequested)
completion(nil) completion(nil)
} }
} }

Loading…
Cancel
Save