@ -13,6 +13,7 @@
#import "Signal - Swift . h "
#import "UIColor + OWS . h "
#import "UIUtil . h "
#import < SignalServiceKit / OWSBlockingManager . h >
NS_ASSUME_NONNULL_BEGIN
@ -20,6 +21,9 @@ NS_ASSUME_NONNULL_BEGIN
UISearchResultsUpdating ,
MFMessageComposeViewControllerDelegate >
@ property ( nonatomic , readonly ) OWSBlockingManager * blockingManager ;
@ property ( nonatomic , readonly ) NSArray < NSString * > * blockedPhoneNumbers ;
@ property ( nonatomic ) IBOutlet UITableViewCell * inviteCell ;
@ property ( nonatomic ) IBOutlet OWSNoSignalContactsView * noSignalContactsView ;
@ -75,7 +79,10 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
_contactsManager = [ Environment getCurrent ] . contactsManager ;
_phoneNumberAccountSet = [ NSMutableSet set ] ;
_blockingManager = [ OWSBlockingManager sharedManager ] ;
_blockedPhoneNumbers = [ _blockingManager blockedPhoneNumbers ] ;
[ self observeNotifications ] ;
return self ;
@ -101,6 +108,10 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
selector : @ selector ( signalRecipientsDidChange : )
name : OWSContactsManagerSignalRecipientsDidChangeNotification
object : nil ] ;
[ [ NSNotificationCenter defaultCenter ] addObserver : self
selector : @ selector ( blockedPhoneNumbersDidChange : )
name : kNSNotificationName_BlockedPhoneNumbersDidChange
object : nil ] ;
}
- ( void ) dealloc
@ -109,7 +120,18 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
}
- ( void ) signalRecipientsDidChange : ( NSNotification * ) notification {
[ self updateContacts ] ;
dispatch_async ( dispatch_get_main_queue ( ) , ^{
[ self updateContacts ] ;
} ) ;
}
- ( void ) blockedPhoneNumbersDidChange : ( id ) notification
{
dispatch_async ( dispatch_get_main_queue ( ) , ^{
_blockedPhoneNumbers = [ _blockingManager blockedPhoneNumbers ] ;
[ self updateContacts ] ;
} ) ;
}
- ( void ) viewDidLoad {
@ -123,7 +145,7 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
self . tableView . estimatedRowHeight = ( CGFloat ) 60.0 ;
self . tableView . rowHeight = UITableViewAutomaticDimension ;
self . contacts = self . contactsManager . signalContacts ;
self . contacts = [ self filteredContacts ] ;
self . searchResults = self . contacts ;
[ self initializeSearch ] ;
@ -241,10 +263,8 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
if ( show ) {
self . searchController . searchBar . hidden = YES ;
self . tableView . backgroundView = _loadingBackgroundView ;
self . refreshControl = nil ;
self . tableView . backgroundView . opaque = YES ;
} else {
[ self initializeRefreshControl ] ;
self . searchController . searchBar . hidden = NO ;
self . tableView . backgroundView = nil ;
}
@ -263,14 +283,11 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
_isNoContactsViewVisible = isNoContactsViewVisible ;
if ( isNoContactsViewVisible ) {
self . refreshControl = nil ;
self . searchController . searchBar . hidden = YES ;
self . tableView . backgroundView = self . noSignalContactsView ;
self . tableView . backgroundView . opaque = YES ;
self . navigationItem . rightBarButtonItem = nil ;
} else {
[ self initializeRefreshControl ] ;
self . refreshControl . enabled = YES ;
self . searchController . searchBar . hidden = NO ;
self . tableView . backgroundView = nil ;
self . navigationItem . rightBarButtonItem = self . createGroupBarButtonItem ;
@ -301,15 +318,6 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
self . searchController . searchBar . searchBarStyle = UISearchBarStyleMinimal ;
self . searchController . searchBar . delegate = self ;
self . searchController . searchBar . placeholder = NSLocalizedString ( @ "SEARCH_BYNAMEORNUMBER_PLACEHOLDER_TEXT ", @ "") ;
[ self initializeRefreshControl ] ;
}
- ( void ) initializeRefreshControl {
UIRefreshControl * refreshControl = [ [ UIRefreshControl alloc ] init ] ;
[ refreshControl addTarget : self action : @ selector ( refreshContacts ) forControlEvents : UIControlEventValueChanged ] ;
self . refreshControl = refreshControl ;
[ self . tableView addSubview : self . refreshControl ] ;
}
#pragma mark - UISearchResultsUpdating
@ -667,46 +675,49 @@ NSString *const MessageComposeTableViewControllerCellContact = @"ContactTableVie
return contact ;
}
#pragma mark Refresh controls
- ( void ) updateContacts {
OWSAssert ( [ NSThread isMainThread ] ) ;
- ( void ) updateAfterRefreshTry {
[ self . refreshControl endRefreshing ] ;
self . contacts = [ self filteredContacts ] ;
[ self updateSearchResultsForSearchController : self . searchController ] ;
[ self . tableView reloadData ] ;
}
[ self showLoadingBackgroundView : NO ] ;
[ self showEmptyBackgroundViewIfNecessary ] ;
- ( BOOL ) isContactBlocked : ( Contact * ) contact
{
if ( contact . parsedPhoneNumbers . count < 1 ) {
return YES ;
}
for ( PhoneNumber * phoneNumber in contact . parsedPhoneNumbers ) {
if ( [ _blockedPhoneNumbers containsObject : phoneNumber . toE164 ] ) {
return YES ;
}
}
return NO ;
}
- ( void ) refreshContacts {
[ [ ContactsUpdater sharedUpdater ] updateSignalContactIntersectionWithABContacts : self . contactsManager . allContacts
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 ] ;
- ( BOOL ) isCurrentUserContact : ( Contact * ) contact
{
for ( PhoneNumber * phoneNumber in contact . parsedPhoneNumbers ) {
if ( [ [ phoneNumber toE164 ] isEqualToString : [ TSAccountManager localNumber ] ] ) {
return YES ;
}
}
return NO ;
}
- ( void ) updateContacts {
self . contacts = self . contactsManager . signalContacts ;
dispatch_async ( dispatch_get_main_queue ( ) , ^{
[ self updateSearchResultsForSearchController : self . searchController ] ;
[ self . tableView reloadData ] ;
[ self updateAfterRefreshTry ] ;
} ) ;
- ( NSArray < Contact * > * _Nonnull ) filteredContacts
{
NSMutableArray < Contact * > * result = [ NSMutableArray new ] ;
for ( Contact * contact in self . contactsManager . signalContacts ) {
if ( ![ self isContactBlocked : contact ] && ![ self isCurrentUserContact : contact ] ) {
[ result addObject : contact ] ;
}
}
return result ;
}
#pragma mark - Navigation