Merge branch 'charlesmchen/contactsViewsVsContactsUpdates'

pull/1/head
Matthew Chen 8 years ago
commit 6d757d3a50

@ -1,5 +1,5 @@
//
// Prefix header for all source files of the 'RedPhone' target in the 'RedPhone' project
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import <Availability.h>
@ -15,8 +15,9 @@
static const NSUInteger ddLogLevel = DDLogLevelInfo;
#endif
#import "iOSVersions.h"
#import <SignalServiceKit/Asserts.h>
#import <SignalServiceKit/OWSDispatch.h>
#import "iOSVersions.h"
#define SignalAlertView(title,msg) [[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil, nil] show]
#define SignalReportError [Pastelog reportErrorAndSubmitLogsWithAlertTitle:NSLocalizedString(@"ERROR_WAS_DETECTED_TITLE", @"") alertBody:NSLocalizedString(@"ERROR_WAS_DETECTED_SUBMIT", @"")];

@ -1,3 +1,7 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import <Contacts/Contacts.h>
#import <Foundation/Foundation.h>
#import <SignalServiceKit/ContactsManagerProtocol.h>
@ -8,6 +12,8 @@
NS_ASSUME_NONNULL_BEGIN
extern NSString *const OWSContactsManagerSignalRecipientsDidChangeNotification;
@class UIFont;
/**

@ -1,3 +1,7 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSContactsManager.h"
#import "ContactsUpdater.h"
#import "Environment.h"
@ -7,6 +11,9 @@
typedef BOOL (^ContactSearchBlock)(id, NSUInteger, BOOL *);
NSString *const OWSContactsManagerSignalRecipientsDidChangeNotification =
@"OWSContactsManagerSignalRecipientsDidChangeNotification";
@interface OWSContactsManager ()
@property id addressBookReference;
@ -99,18 +106,27 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
- (void)intersectContacts {
[[ContactsUpdater sharedUpdater] updateSignalContactIntersectionWithABContacts:self.allContacts
success:^{
DDLogInfo(@"%@ Successfully intersected contacts.", self.tag);
}
failure:^(NSError *error) {
DDLogWarn(@"%@ Failed to intersect contacts with error: %@. Rescheduling", self.tag, error);
[NSTimer scheduledTimerWithTimeInterval:60
target:self
selector:@selector(intersectContacts)
userInfo:nil
repeats:NO];
}];
success:^{
DDLogInfo(@"%@ Successfully intersected contacts.", self.tag);
[self fireSignalRecipientsDidChange];
}
failure:^(NSError *error) {
DDLogWarn(@"%@ Failed to intersect contacts with error: %@. Rescheduling", self.tag, error);
[NSTimer scheduledTimerWithTimeInterval:60
target:self
selector:@selector(intersectContacts)
userInfo:nil
repeats:NO];
}];
}
- (void)fireSignalRecipientsDidChange
{
AssertIsOnMainThread();
[[NSNotificationCenter defaultCenter] postNotificationName:OWSContactsManagerSignalRecipientsDidChangeNotification
object:nil];
}
- (void)pullLatestAddressBook {

@ -77,6 +77,8 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
_contactsManager = [Environment getCurrent].contactsManager;
_phoneNumberAccountSet = [NSMutableSet set];
[self observeNotifications];
return self;
}
@ -89,9 +91,28 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
_contactsManager = [Environment getCurrent].contactsManager;
[self observeNotifications];
return self;
}
- (void)observeNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(signalRecipientsDidChange:)
name:OWSContactsManagerSignalRecipientsDidChangeNotification
object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)signalRecipientsDidChange:(NSNotification *)notification {
[self updateContacts];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.navigationBar setTranslucent:NO];
@ -612,32 +633,36 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
- (void)refreshContacts {
[[ContactsUpdater sharedUpdater] updateSignalContactIntersectionWithABContacts:self.contactsManager.allContacts
success:^{
self.contacts = self.contactsManager.signalContacts;
dispatch_async(dispatch_get_main_queue(), ^{
[self updateSearchResultsForSearchController:self.searchController];
[self.tableView reloadData];
[self updateAfterRefreshTry];
});
}
failure:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR_WAS_DETECTED_TITLE", @"")
message:NSLocalizedString(@"TIMEOUT_CONTACTS_DETAIL", @"")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[alert show];
[self updateAfterRefreshTry];
});
}];
success:^{
[self updateContacts];
}
failure:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR_WAS_DETECTED_TITLE", @"")
message:NSLocalizedString(@"TIMEOUT_CONTACTS_DETAIL", @"")
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", @"")
otherButtonTitles:nil];
[alert show];
[self updateAfterRefreshTry];
});
}];
if ([self.contacts count] == 0) {
[self showLoadingBackgroundView:YES];
}
}
- (void)updateContacts {
self.contacts = self.contactsManager.signalContacts;
dispatch_async(dispatch_get_main_queue(), ^{
[self updateSearchResultsForSearchController:self.searchController];
[self.tableView reloadData];
[self updateAfterRefreshTry];
});
}
#pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender

@ -1,9 +1,5 @@
//
// NewGroupViewController.m
// Signal
//
// Created by Dylan Bourgeois on 13/11/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "NewGroupViewController.h"
@ -68,6 +64,33 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
contactsUpdater:[Environment getCurrent].contactsUpdater];
_contactsManager = [Environment getCurrent].contactsManager;
[self observeNotifications];
}
- (void)observeNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(signalRecipientsDidChange:)
name:OWSContactsManagerSignalRecipientsDidChangeNotification
object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)signalRecipientsDidChange:(NSNotification *)notification {
[self updateContacts];
}
- (void)updateContacts {
AssertIsOnMainThread();
contacts = self.contactsManager.signalContacts;
[self.tableView reloadData];
}
- (void)configWithThread:(TSGroupThread *)gThread {
@ -78,7 +101,7 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
[super viewDidLoad];
[self.navigationController.navigationBar setTranslucent:NO];
contacts = [Environment getCurrent].contactsManager.signalContacts;
contacts = self.contactsManager.signalContacts;
self.tableView.tableHeaderView.frame = CGRectMake(0, 0, 400, 44);

Loading…
Cancel
Save