diff --git a/Signal/src/ViewControllers/NewGroupViewController.m b/Signal/src/ViewControllers/NewGroupViewController.m index f431ef8ee..83c806bfd 100644 --- a/Signal/src/ViewControllers/NewGroupViewController.m +++ b/Signal/src/ViewControllers/NewGroupViewController.m @@ -206,9 +206,7 @@ NS_ASSUME_NONNULL_BEGIN [nonContactsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ NewGroupViewController *strongSelf = weakSelf; - if (!strongSelf) { - return (ContactTableViewCell *)nil; - } + OWSAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId]; @@ -262,9 +260,7 @@ NS_ASSUME_NONNULL_BEGIN [signalAccountSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ NewGroupViewController *strongSelf = weakSelf; - if (!strongSelf) { - return (ContactTableViewCell *)nil; - } + OWSAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; @@ -439,7 +435,7 @@ NS_ASSUME_NONNULL_BEGIN - (TSGroupModel *)makeGroup { NSString *title = self.groupNameTextField.text; - NSMutableArray *recipientIds = [self.memberRecipientIds.allObjects mutableCopy]; + NSMutableArray *recipientIds = [self.memberRecipientIds.allObjects mutableCopy]; [recipientIds addObject:[self.contactsViewHelper localNumber]]; NSData *groupId = [SecurityUtils generateRandomBytes:16]; diff --git a/Signal/src/ViewControllers/SelectRecipientViewController.h b/Signal/src/ViewControllers/SelectRecipientViewController.h index 090493bcf..4d43b62e7 100644 --- a/Signal/src/ViewControllers/SelectRecipientViewController.h +++ b/Signal/src/ViewControllers/SelectRecipientViewController.h @@ -4,6 +4,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + @class SignalAccount; @protocol SelectRecipientViewControllerDelegate @@ -39,3 +41,5 @@ @property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper; @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/SelectRecipientViewController.m b/Signal/src/ViewControllers/SelectRecipientViewController.m index 6ab7ba914..377587851 100644 --- a/Signal/src/ViewControllers/SelectRecipientViewController.m +++ b/Signal/src/ViewControllers/SelectRecipientViewController.m @@ -11,6 +11,7 @@ #import "OWSContactsManager.h" #import "OWSTableViewController.h" #import "PhoneNumber.h" +#import "Signal-Swift.h" #import "SignalAccount.h" #import "StringUtil.h" #import "UIFont+OWS.h" @@ -244,6 +245,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien OWSAssert(self.delegate); if (![self hasValidPhoneNumber]) { + DDLogError(@"Invalid phone number was selected."); OWSAssert(0); return; } @@ -257,6 +259,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien [possiblePhoneNumbers addObject:phoneNumber.toE164]; } if ([possiblePhoneNumbers count] < 1) { + DDLogError(@"Couldn't parse phone number."); OWSAssert(0); return; } @@ -278,7 +281,9 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien handler:^(UIAlertAction *_Nonnull action) { wasCancelled = YES; }]]; - [ViewControllerUtils.topMostController presentViewController:activityAlert animated:YES completion:nil]; + [[UIApplication sharedApplication].frontmostViewController presentViewController:activityAlert + animated:YES + completion:nil]; __weak SelectRecipientViewController *weakSelf = self; [[ContactsUpdater sharedUpdater] lookupIdentifiers:possiblePhoneNumbers @@ -353,6 +358,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien [self updateCountryWithName:countryName callingCode:callingCode countryCode:countryCode]; + // Trigger the formatting logic with a no-op edit. [self textField:self.phoneNumberTextField shouldChangeCharactersInRange:NSMakeRange(0, 0) replacementString:@""]; } @@ -377,7 +383,9 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; - [self tryToSelectPhoneNumber]; + if ([self hasValidPhoneNumber]) { + [self tryToSelectPhoneNumber]; + } return NO; } @@ -397,17 +405,14 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien const CGFloat kButtonRowHeight = 60; [phoneNumberSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ SelectRecipientViewController *strongSelf = weakSelf; - if (!strongSelf) { - return (UITableViewCell *)nil; - } + OWSAssert(strongSelf); UITableViewCell *cell = [UITableViewCell new]; // Country Row UIView *countryRow = [self createRowWithHeight:kCountryRowHeight previousRow:nil superview:cell.contentView]; - [countryRow - addGestureRecognizer:[[OWSAnyTouchGestureRecognizer alloc] initWithTarget:self - action:@selector(countryRowTouched:)]]; + [countryRow addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(countryRowTouched:)]]; UILabel *countryCodeLabel = self.countryCodeLabel; [countryRow addSubview:countryCodeLabel]; @@ -421,9 +426,9 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien // Phone Number Row UIView *phoneNumberRow = [self createRowWithHeight:kPhoneNumberRowHeight previousRow:countryRow superview:cell.contentView]; - [phoneNumberRow addGestureRecognizer:[[OWSAnyTouchGestureRecognizer alloc] - initWithTarget:self - action:@selector(phoneNumberRowTouched:)]]; + [phoneNumberRow + addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(phoneNumberRowTouched:)]]; UILabel *phoneNumberLabel = self.phoneNumberLabel; [phoneNumberRow addSubview:phoneNumberLabel]; @@ -476,9 +481,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien for (SignalAccount *signalAccount in signalAccounts) { [contactsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ SelectRecipientViewController *strongSelf = weakSelf; - if (!strongSelf) { - return (ContactTableViewCell *)nil; - } + OWSAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; BOOL isBlocked = [helper isRecipientIdBlocked:signalAccount.recipientId]; diff --git a/Signal/src/ViewControllers/SelectThreadViewController.m b/Signal/src/ViewControllers/SelectThreadViewController.m index d9b50820a..cc9b5fa88 100644 --- a/Signal/src/ViewControllers/SelectThreadViewController.m +++ b/Signal/src/ViewControllers/SelectThreadViewController.m @@ -136,9 +136,7 @@ NS_ASSUME_NONNULL_BEGIN for (TSThread *thread in [self filteredThreadsWithSearchText]) { [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ SelectThreadViewController *strongSelf = weakSelf; - if (!strongSelf) { - return (ContactTableViewCell *)nil; - } + OWSAssert(strongSelf); // To be consistent with the threads (above), we use ContactTableViewCell // instead of InboxTableViewCell to present contacts and threads. @@ -157,9 +155,7 @@ NS_ASSUME_NONNULL_BEGIN for (SignalAccount *signalAccount in filteredSignalAccounts) { [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ SelectThreadViewController *strongSelf = weakSelf; - if (!strongSelf) { - return (ContactTableViewCell *)nil; - } + OWSAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; BOOL isBlocked = [helper isRecipientIdBlocked:signalAccount.recipientId]; diff --git a/Signal/src/ViewControllers/ShowGroupMembersViewController.m b/Signal/src/ViewControllers/ShowGroupMembersViewController.m index ed4986a97..2a33ab839 100644 --- a/Signal/src/ViewControllers/ShowGroupMembersViewController.m +++ b/Signal/src/ViewControllers/ShowGroupMembersViewController.m @@ -103,9 +103,7 @@ NS_ASSUME_NONNULL_BEGIN for (NSString *recipientId in [memberRecipientIds.allObjects sortedArrayUsingSelector:@selector(compare:)]) { [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ ShowGroupMembersViewController *strongSelf = weakSelf; - if (!strongSelf) { - return (ContactTableViewCell *)nil; - } + OWSAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; SignalAccount *signalAccount = [helper signalAccountForRecipientId:recipientId]; @@ -165,7 +163,9 @@ NS_ASSUME_NONNULL_BEGIN fromViewController:self blockingManager:helper.blockingManager contactsManager:helper.contactsManager - completionBlock:nil]; + completionBlock:^(BOOL ignore) { + [self updateTableContents]; + }]; }]]; } else { [actionSheetController @@ -178,7 +178,9 @@ NS_ASSUME_NONNULL_BEGIN fromViewController:self blockingManager:helper.blockingManager contactsManager:helper.contactsManager - completionBlock:nil]; + completionBlock:^(BOOL ignore) { + [self updateTableContents]; + }]; }]]; } } else { @@ -194,7 +196,9 @@ NS_ASSUME_NONNULL_BEGIN fromViewController:self blockingManager:helper.blockingManager contactsManager:helper.contactsManager - completionBlock:nil]; + completionBlock:^(BOOL ignore) { + [self updateTableContents]; + }]; }]]; } else { [actionSheetController @@ -207,7 +211,9 @@ NS_ASSUME_NONNULL_BEGIN fromViewController:self blockingManager:helper.blockingManager contactsManager:helper.contactsManager - completionBlock:nil]; + completionBlock:^(BOOL ignore) { + [self updateTableContents]; + }]; }]]; } } diff --git a/Signal/src/ViewControllers/SignalAccount.h b/Signal/src/ViewControllers/SignalAccount.h index 34994efe9..0f3157973 100644 --- a/Signal/src/ViewControllers/SignalAccount.h +++ b/Signal/src/ViewControllers/SignalAccount.h @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN // non-contact account. @property (nonatomic, nullable) Contact *contact; -@property (nonatomic) BOOL isMultipleAccountContact; +@property (nonatomic) BOOL hasMultipleAccountContact; // For contacts with more than one signal account, // this is a label for the account. diff --git a/Signal/src/ViewControllers/UpdateGroupViewController.m b/Signal/src/ViewControllers/UpdateGroupViewController.m index 7cf3494c9..3f4be9c99 100644 --- a/Signal/src/ViewControllers/UpdateGroupViewController.m +++ b/Signal/src/ViewControllers/UpdateGroupViewController.m @@ -246,9 +246,7 @@ NS_ASSUME_NONNULL_BEGIN [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ UpdateGroupViewController *strongSelf = weakSelf; - if (!strongSelf) { - return (ContactTableViewCell *)nil; - } + OWSAssert(strongSelf); ContactTableViewCell *cell = [ContactTableViewCell new]; SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId]; diff --git a/Signal/src/ViewControllers/ViewControllerUtils.h b/Signal/src/ViewControllers/ViewControllerUtils.h index c5c16bb9b..8e478fb6a 100644 --- a/Signal/src/ViewControllers/ViewControllerUtils.h +++ b/Signal/src/ViewControllers/ViewControllerUtils.h @@ -28,6 +28,4 @@ message:(NSString *)message buttonLabel:(NSString *)buttonLabel; -+ (UIViewController *)topMostController; - @end diff --git a/Signal/src/ViewControllers/ViewControllerUtils.m b/Signal/src/ViewControllers/ViewControllerUtils.m index cd16e21de..180e25fcc 100644 --- a/Signal/src/ViewControllers/ViewControllerUtils.m +++ b/Signal/src/ViewControllers/ViewControllerUtils.m @@ -5,6 +5,7 @@ #import "ViewControllerUtils.h" #import "Environment.h" #import "PhoneNumber.h" +#import "Signal-Swift.h" #import "SignalsViewController.h" #import "StringUtil.h" #import @@ -117,23 +118,11 @@ NS_ASSUME_NONNULL_BEGIN [alert addAction:[UIAlertAction actionWithTitle:buttonLabel style:UIAlertActionStyleDefault handler:nil]]; - [self.topMostController presentViewController:alert animated:YES completion:nil]; + [[UIApplication sharedApplication].frontmostViewController presentViewController:alert animated:YES completion:nil]; return alert; } -+ (UIViewController *)topMostController -{ - UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController; - - while (topController.presentedViewController) { - topController = topController.presentedViewController; - } - - OWSAssert(topController); - return topController; -} - #pragma mark - Logging + (NSString *)tag diff --git a/Signal/src/contact/OWSContactsManager.m b/Signal/src/contact/OWSContactsManager.m index 7eb2395b3..66503f297 100644 --- a/Signal/src/contact/OWSContactsManager.m +++ b/Signal/src/contact/OWSContactsManager.m @@ -214,7 +214,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in SignalAccount *signalAccount = [[SignalAccount alloc] initWithSignalRecipient:signalRecipient]; signalAccount.contact = contact; if (signalRecipients.count > 1) { - signalAccount.isMultipleAccountContact = YES; + signalAccount.hasMultipleAccountContact = YES; signalAccount.multipleAccountLabel = [[self class] accountLabelForContact:contact recipientId:signalRecipient.recipientId]; } @@ -562,7 +562,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in NSString *baseName = (signalAccount.contact ? [self displayNameForContact:signalAccount.contact] : [self displayNameForPhoneIdentifier:signalAccount.recipientId]); - OWSAssert(signalAccount.isMultipleAccountContact == (signalAccount.multipleAccountLabel != nil)); + OWSAssert(signalAccount.hasMultipleAccountContact == (signalAccount.multipleAccountLabel != nil)); if (signalAccount.multipleAccountLabel) { return [NSString stringWithFormat:@"%@ (%@)", baseName, signalAccount.multipleAccountLabel]; } else { @@ -577,7 +577,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in OWSAssert(font); NSAttributedString *baseName = [self formattedFullNameForContact:signalAccount.contact font:font]; - OWSAssert(signalAccount.isMultipleAccountContact == (signalAccount.multipleAccountLabel != nil)); + OWSAssert(signalAccount.hasMultipleAccountContact == (signalAccount.multipleAccountLabel != nil)); if (signalAccount.multipleAccountLabel) { NSMutableAttributedString *result = [NSMutableAttributedString new]; [result appendAttributedString:baseName];