Merge branch 'charlesmchen/pullToRefreshContacts'

pull/1/head
Matthew Chen 8 years ago
commit 9ee25fd607

@ -113,9 +113,25 @@ NS_ASSUME_NONNULL_BEGIN
[self.noSignalContactsView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[self.noSignalContactsView autoPinToBottomLayoutGuideOfViewController:self withInset:0];
UIRefreshControl *pullToRefreshView = [UIRefreshControl new];
pullToRefreshView.tintColor = [UIColor grayColor];
[pullToRefreshView addTarget:self
action:@selector(pullToRefreshPerformed:)
forControlEvents:UIControlEventValueChanged];
[self.tableViewController.tableView insertSubview:pullToRefreshView atIndex:0];
[self updateTableContents];
}
- (void)pullToRefreshPerformed:(UIRefreshControl *)refreshControl
{
OWSAssert([NSThread isMainThread]);
[self.contactsViewHelper.contactsManager fetchSystemContactsIfAlreadyAuthorizedAndIgnoreDebounce];
[refreshControl endRefreshing];
}
- (void)showContactsPermissionReminder:(BOOL)isVisible
{
_hideContactsPermissionReminderViewConstraint.active = !isVisible;
@ -789,6 +805,18 @@ NS_ASSUME_NONNULL_BEGIN
}
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END

@ -55,6 +55,7 @@ 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)fetchSystemContactsIfAlreadyAuthorizedAndIgnoreDebounce;
#pragma mark - Util

@ -80,7 +80,12 @@ NSString *const kTSStorageManager_AccountLastNames = @"kTSStorageManager_Account
- (void)fetchSystemContactsIfAlreadyAuthorized
{
[self.systemContactsFetcher fetchIfAlreadyAuthorized];
[self.systemContactsFetcher fetchIfAlreadyAuthorizedWithIgnoreDebounce:NO];
}
- (void)fetchSystemContactsIfAlreadyAuthorizedAndIgnoreDebounce
{
[self.systemContactsFetcher fetchIfAlreadyAuthorizedWithIgnoreDebounce:YES];
}
- (BOOL)isSystemContactsAuthorized

@ -417,16 +417,16 @@ class SystemContactsFetcher: NSObject {
}
}
public func fetchIfAlreadyAuthorized() {
public func fetchIfAlreadyAuthorized(ignoreDebounce: Bool = false) {
AssertIsOnMainThread()
guard authorizationStatus == .authorized else {
return
}
updateContacts(completion: nil)
updateContacts(completion: nil, ignoreDebounce:ignoreDebounce)
}
private func updateContacts(completion: ((Error?) -> Void)?) {
private func updateContacts(completion: ((Error?) -> Void)?, ignoreDebounce: Bool = false) {
AssertIsOnMainThread()
systemContactsHaveBeenRequestedAtLeastOnce = true
@ -457,6 +457,9 @@ class SystemContactsFetcher: NSObject {
if self.lastContactUpdateHash != contactsHash {
Logger.info("\(self.TAG) contact hash changed. new contactsHash: \(contactsHash)")
shouldNotifyDelegate = true
} else if ignoreDebounce {
Logger.info("\(self.TAG) ignoring debounce.")
shouldNotifyDelegate = true
} else {
// If nothing has changed, only notify delegate (to perform contact intersection) every N hours

Loading…
Cancel
Save