CR: clarify names, comments, asserts

// FREEBIE
pull/1/head
Michael Kirk 7 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,
// 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

@ -131,9 +131,9 @@ NSString *const OWSContactsManagerSignalAccountsDidChangeNotification
- (void)systemContactsFetcher:(SystemContactsFetcher *)systemsContactsFetcher
updatedContacts:(NSArray<Contact *> *)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<Contact *> *)contacts clearStaleCache:(BOOL)clearStaleCache
- (void)updateWithContacts:(NSArray<Contact *> *)contacts shouldClearStaleCache:(BOOL)shouldClearStaleCache
{
dispatch_async(self.serialQueue, ^{
NSMutableDictionary<NSString *, Contact *> *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<SignalAccount *> *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);

@ -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)
}
}

Loading…
Cancel
Save