Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 1b3b5fc9e5
commit 5af6b6f213

@ -523,7 +523,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
// Avoid blocking app launch by putting all further possible DB access in async block
dispatch_async(dispatch_get_main_queue(), ^{
[TSSocketManager requestSocketOpen];
[[Environment getCurrent].contactsManager fetchSystemContactsIfAlreadyAuthorized];
[[Environment getCurrent].contactsManager fetchSystemContactsOnceIfAlreadyAuthorized];
// This will fetch new messages, if we're using domain fronting.
[[PushManager sharedManager] applicationDidBecomeActive];

@ -71,7 +71,9 @@ extern NSString *const OWSContactsManagerSignalAccountsDidChangeNotification;
// Ensure's the app has the latest contacts, but won't prompt the user for contact
// access if they haven't granted it.
- (void)fetchSystemContactsIfAlreadyAuthorized;
- (void)fetchSystemContactsOnceIfAlreadyAuthorized;
// This variant will fetch system contacts if contact access has already been granted,
// but not prompt for contact access. Also, it will always fire a notification.
- (void)fetchSystemContactsIfAlreadyAuthorizedAndAlwaysNotify;
#pragma mark - Util

@ -93,14 +93,14 @@ NSString *const kTSStorageManager_lastKnownContactRecipientIds = @"lastKnownCont
[self.systemContactsFetcher requestOnceWithCompletion:completion];
}
- (void)fetchSystemContactsIfAlreadyAuthorized
- (void)fetchSystemContactsOnceIfAlreadyAuthorized
{
[self.systemContactsFetcher fetchIfAlreadyAuthorizedWithAlwaysNotify:NO];
[self.systemContactsFetcher fetchOnceIfAlreadyAuthorized];
}
- (void)fetchSystemContactsIfAlreadyAuthorizedAndAlwaysNotify
{
[self.systemContactsFetcher fetchIfAlreadyAuthorizedWithAlwaysNotify:YES];
[self.systemContactsFetcher fetchIfAlreadyAuthorizedAndAlwaysNotify];
}
- (BOOL)isSystemContactsAuthorized

@ -344,7 +344,6 @@ class SystemContactsFetcher: NSObject {
private var systemContactsHaveBeenRequestedAtLeastOnce = false
private var hasSetupObservation = false
private var isFetchingContacts = false
override init() {
self.contactStoreAdapter = ContactStoreAdapter()
@ -362,8 +361,7 @@ class SystemContactsFetcher: NSObject {
hasSetupObservation = true
self.contactStoreAdapter.startObservingChanges { [weak self] in
DispatchQueue.main.async {
// If contacts have changed, don't de-bounce.
self?.updateContacts(completion: nil, alwaysNotify: false, shouldDebounce: false)
self?.updateContacts(completion: nil, alwaysNotify: false)
}
}
}
@ -382,7 +380,6 @@ class SystemContactsFetcher: NSObject {
completion?(nil)
return
}
systemContactsHaveBeenRequestedAtLeastOnce = true
setupObservationIfNecessary()
switch authorizationStatus {
@ -419,33 +416,28 @@ class SystemContactsFetcher: NSObject {
}
}
public func fetchIfAlreadyAuthorized(alwaysNotify: Bool = false) {
public func fetchOnceIfAlreadyAuthorized() {
AssertIsOnMainThread()
guard authorizationStatus == .authorized else {
return
}
updateContacts(completion: nil, alwaysNotify:alwaysNotify)
guard !systemContactsHaveBeenRequestedAtLeastOnce else {
return
}
private func tryToAcquireContactFetchLock() -> Bool {
var didAcquireLock = false
objc_sync_enter(self)
if !self.isFetchingContacts {
self.isFetchingContacts = true
didAcquireLock = true
updateContacts(completion: nil, alwaysNotify:false)
}
objc_sync_exit(self)
return didAcquireLock
public func fetchIfAlreadyAuthorizedAndAlwaysNotify() {
AssertIsOnMainThread()
guard authorizationStatus == .authorized else {
return
}
private func releaseContactFetchLock() {
objc_sync_enter(self)
self.isFetchingContacts = false
objc_sync_exit(self)
updateContacts(completion: nil, alwaysNotify:true)
}
private func updateContacts(completion: ((Error?) -> Void)?, alwaysNotify: Bool = false, shouldDebounce: Bool = true) {
private func updateContacts(completion: ((Error?) -> Void)?, alwaysNotify: Bool = false) {
AssertIsOnMainThread()
systemContactsHaveBeenRequestedAtLeastOnce = true
@ -453,18 +445,6 @@ class SystemContactsFetcher: NSObject {
DispatchQueue.global().async {
if shouldDebounce {
guard self.tryToAcquireContactFetchLock() else {
Logger.info("\(self.TAG) ignoring redundant system contacts fetch.")
return
}
}
defer {
if shouldDebounce {
self.releaseContactFetchLock()
}
}
Logger.info("\(self.TAG) fetching contacts")
var fetchedContacts: [Contact]?

Loading…
Cancel
Save