Update views that show contacts to reflect updates.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent c087c56b0c
commit adfbcc3e27

@ -15,8 +15,9 @@
static const NSUInteger ddLogLevel = DDLogLevelInfo; static const NSUInteger ddLogLevel = DDLogLevelInfo;
#endif #endif
#import "iOSVersions.h"
#import <SignalServiceKit/Asserts.h> #import <SignalServiceKit/Asserts.h>
#import "iOSVersions.h"
#import "OWSDispatch.h"
#define SignalAlertView(title,msg) [[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil, nil] show] #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", @"")]; #define SignalReportError [Pastelog reportErrorAndSubmitLogsWithAlertTitle:NSLocalizedString(@"ERROR_WAS_DETECTED_TITLE", @"") alertBody:NSLocalizedString(@"ERROR_WAS_DETECTED_SUBMIT", @"")];

@ -8,6 +8,8 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
extern NSString *const OWSContactsManagerContactsDidChangeNotification;
@class UIFont; @class UIFont;
/** /**

@ -7,6 +7,8 @@
typedef BOOL (^ContactSearchBlock)(id, NSUInteger, BOOL *); typedef BOOL (^ContactSearchBlock)(id, NSUInteger, BOOL *);
NSString *const OWSContactsManagerContactsDidChangeNotification = @"OWSContactsManagerContactsDidChangeNotification";
@interface OWSContactsManager () @interface OWSContactsManager ()
@property id addressBookReference; @property id addressBookReference;
@ -99,18 +101,26 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
- (void)intersectContacts { - (void)intersectContacts {
[[ContactsUpdater sharedUpdater] updateSignalContactIntersectionWithABContacts:self.allContacts [[ContactsUpdater sharedUpdater] updateSignalContactIntersectionWithABContacts:self.allContacts
success:^{ success:^{
DDLogInfo(@"%@ Successfully intersected contacts.", self.tag); DDLogInfo(@"%@ Successfully intersected contacts.", self.tag);
} [self fireContactsDidChange];
failure:^(NSError *error) { }
DDLogWarn(@"%@ Failed to intersect contacts with error: %@. Rescheduling", self.tag, error); failure:^(NSError *error) {
DDLogWarn(@"%@ Failed to intersect contacts with error: %@. Rescheduling", self.tag, error);
[NSTimer scheduledTimerWithTimeInterval:60
target:self [NSTimer scheduledTimerWithTimeInterval:60
selector:@selector(intersectContacts) target:self
userInfo:nil selector:@selector(intersectContacts)
repeats:NO]; userInfo:nil
}]; repeats:NO];
}];
}
- (void)fireContactsDidChange {
AssertIsOnMainThread();
[[NSNotificationCenter defaultCenter] postNotificationName:OWSContactsManagerContactsDidChangeNotification
object:nil];
} }
- (void)pullLatestAddressBook { - (void)pullLatestAddressBook {

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

@ -68,6 +68,33 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
contactsUpdater:[Environment getCurrent].contactsUpdater]; contactsUpdater:[Environment getCurrent].contactsUpdater];
_contactsManager = [Environment getCurrent].contactsManager; _contactsManager = [Environment getCurrent].contactsManager;
[self observeNotifications];
}
- (void)observeNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(contactsDidChange:)
name:OWSContactsManagerContactsDidChangeNotification
object:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)contactsDidChange:(NSNotification *)notification {
[self updateContacts];
}
- (void)updateContacts {
AssertIsOnMainThread();
contacts = self.contactsManager.signalContacts;
[self.tableView reloadData];
} }
- (void)configWithThread:(TSGroupThread *)gThread { - (void)configWithThread:(TSGroupThread *)gThread {
@ -78,7 +105,7 @@ static NSString *const kUnwindToMessagesViewSegue = @"UnwindToMessagesViewSegue"
[super viewDidLoad]; [super viewDidLoad];
[self.navigationController.navigationBar setTranslucent:NO]; [self.navigationController.navigationBar setTranslucent:NO];
contacts = [Environment getCurrent].contactsManager.signalContacts; contacts = self.contactsManager.signalContacts;
self.tableView.tableHeaderView.frame = CGRectMake(0, 0, 400, 44); self.tableView.tableHeaderView.frame = CGRectMake(0, 0, 400, 44);

Loading…
Cancel
Save