Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 2bec1db541
commit f71ec9f7cb

@ -206,9 +206,7 @@ NS_ASSUME_NONNULL_BEGIN
[nonContactsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ [nonContactsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
NewGroupViewController *strongSelf = weakSelf; NewGroupViewController *strongSelf = weakSelf;
if (!strongSelf) { OWSAssert(strongSelf);
return (ContactTableViewCell *)nil;
}
ContactTableViewCell *cell = [ContactTableViewCell new]; ContactTableViewCell *cell = [ContactTableViewCell new];
SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId]; SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId];
@ -262,9 +260,7 @@ NS_ASSUME_NONNULL_BEGIN
[signalAccountSection [signalAccountSection
addItem:[OWSTableItem itemWithCustomCellBlock:^{ addItem:[OWSTableItem itemWithCustomCellBlock:^{
NewGroupViewController *strongSelf = weakSelf; NewGroupViewController *strongSelf = weakSelf;
if (!strongSelf) { OWSAssert(strongSelf);
return (ContactTableViewCell *)nil;
}
ContactTableViewCell *cell = [ContactTableViewCell new]; ContactTableViewCell *cell = [ContactTableViewCell new];
@ -439,7 +435,7 @@ NS_ASSUME_NONNULL_BEGIN
- (TSGroupModel *)makeGroup - (TSGroupModel *)makeGroup
{ {
NSString *title = self.groupNameTextField.text; NSString *title = self.groupNameTextField.text;
NSMutableArray *recipientIds = [self.memberRecipientIds.allObjects mutableCopy]; NSMutableArray<NSString *> *recipientIds = [self.memberRecipientIds.allObjects mutableCopy];
[recipientIds addObject:[self.contactsViewHelper localNumber]]; [recipientIds addObject:[self.contactsViewHelper localNumber]];
NSData *groupId = [SecurityUtils generateRandomBytes:16]; NSData *groupId = [SecurityUtils generateRandomBytes:16];

@ -4,6 +4,8 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class SignalAccount; @class SignalAccount;
@protocol SelectRecipientViewControllerDelegate <NSObject> @protocol SelectRecipientViewControllerDelegate <NSObject>
@ -39,3 +41,5 @@
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper; @property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
@end @end
NS_ASSUME_NONNULL_END

@ -11,6 +11,7 @@
#import "OWSContactsManager.h" #import "OWSContactsManager.h"
#import "OWSTableViewController.h" #import "OWSTableViewController.h"
#import "PhoneNumber.h" #import "PhoneNumber.h"
#import "Signal-Swift.h"
#import "SignalAccount.h" #import "SignalAccount.h"
#import "StringUtil.h" #import "StringUtil.h"
#import "UIFont+OWS.h" #import "UIFont+OWS.h"
@ -244,6 +245,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
OWSAssert(self.delegate); OWSAssert(self.delegate);
if (![self hasValidPhoneNumber]) { if (![self hasValidPhoneNumber]) {
DDLogError(@"Invalid phone number was selected.");
OWSAssert(0); OWSAssert(0);
return; return;
} }
@ -257,6 +259,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
[possiblePhoneNumbers addObject:phoneNumber.toE164]; [possiblePhoneNumbers addObject:phoneNumber.toE164];
} }
if ([possiblePhoneNumbers count] < 1) { if ([possiblePhoneNumbers count] < 1) {
DDLogError(@"Couldn't parse phone number.");
OWSAssert(0); OWSAssert(0);
return; return;
} }
@ -278,7 +281,9 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
handler:^(UIAlertAction *_Nonnull action) { handler:^(UIAlertAction *_Nonnull action) {
wasCancelled = YES; wasCancelled = YES;
}]]; }]];
[ViewControllerUtils.topMostController presentViewController:activityAlert animated:YES completion:nil]; [[UIApplication sharedApplication].frontmostViewController presentViewController:activityAlert
animated:YES
completion:nil];
__weak SelectRecipientViewController *weakSelf = self; __weak SelectRecipientViewController *weakSelf = self;
[[ContactsUpdater sharedUpdater] lookupIdentifiers:possiblePhoneNumbers [[ContactsUpdater sharedUpdater] lookupIdentifiers:possiblePhoneNumbers
@ -353,6 +358,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
[self updateCountryWithName:countryName callingCode:callingCode countryCode:countryCode]; [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:@""]; [self textField:self.phoneNumberTextField shouldChangeCharactersInRange:NSMakeRange(0, 0) replacementString:@""];
} }
@ -377,7 +383,9 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
- (BOOL)textFieldShouldReturn:(UITextField *)textField - (BOOL)textFieldShouldReturn:(UITextField *)textField
{ {
[textField resignFirstResponder]; [textField resignFirstResponder];
[self tryToSelectPhoneNumber]; if ([self hasValidPhoneNumber]) {
[self tryToSelectPhoneNumber];
}
return NO; return NO;
} }
@ -397,17 +405,14 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
const CGFloat kButtonRowHeight = 60; const CGFloat kButtonRowHeight = 60;
[phoneNumberSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ [phoneNumberSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
SelectRecipientViewController *strongSelf = weakSelf; SelectRecipientViewController *strongSelf = weakSelf;
if (!strongSelf) { OWSAssert(strongSelf);
return (UITableViewCell *)nil;
}
UITableViewCell *cell = [UITableViewCell new]; UITableViewCell *cell = [UITableViewCell new];
// Country Row // Country Row
UIView *countryRow = [self createRowWithHeight:kCountryRowHeight previousRow:nil superview:cell.contentView]; UIView *countryRow = [self createRowWithHeight:kCountryRowHeight previousRow:nil superview:cell.contentView];
[countryRow [countryRow addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
addGestureRecognizer:[[OWSAnyTouchGestureRecognizer alloc] initWithTarget:self action:@selector(countryRowTouched:)]];
action:@selector(countryRowTouched:)]];
UILabel *countryCodeLabel = self.countryCodeLabel; UILabel *countryCodeLabel = self.countryCodeLabel;
[countryRow addSubview:countryCodeLabel]; [countryRow addSubview:countryCodeLabel];
@ -421,9 +426,9 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
// Phone Number Row // Phone Number Row
UIView *phoneNumberRow = UIView *phoneNumberRow =
[self createRowWithHeight:kPhoneNumberRowHeight previousRow:countryRow superview:cell.contentView]; [self createRowWithHeight:kPhoneNumberRowHeight previousRow:countryRow superview:cell.contentView];
[phoneNumberRow addGestureRecognizer:[[OWSAnyTouchGestureRecognizer alloc] [phoneNumberRow
initWithTarget:self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(phoneNumberRowTouched:)]]; action:@selector(phoneNumberRowTouched:)]];
UILabel *phoneNumberLabel = self.phoneNumberLabel; UILabel *phoneNumberLabel = self.phoneNumberLabel;
[phoneNumberRow addSubview:phoneNumberLabel]; [phoneNumberRow addSubview:phoneNumberLabel];
@ -476,9 +481,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
for (SignalAccount *signalAccount in signalAccounts) { for (SignalAccount *signalAccount in signalAccounts) {
[contactsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{ [contactsSection addItem:[OWSTableItem itemWithCustomCellBlock:^{
SelectRecipientViewController *strongSelf = weakSelf; SelectRecipientViewController *strongSelf = weakSelf;
if (!strongSelf) { OWSAssert(strongSelf);
return (ContactTableViewCell *)nil;
}
ContactTableViewCell *cell = [ContactTableViewCell new]; ContactTableViewCell *cell = [ContactTableViewCell new];
BOOL isBlocked = [helper isRecipientIdBlocked:signalAccount.recipientId]; BOOL isBlocked = [helper isRecipientIdBlocked:signalAccount.recipientId];

@ -136,9 +136,7 @@ NS_ASSUME_NONNULL_BEGIN
for (TSThread *thread in [self filteredThreadsWithSearchText]) { for (TSThread *thread in [self filteredThreadsWithSearchText]) {
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section addItem:[OWSTableItem itemWithCustomCellBlock:^{
SelectThreadViewController *strongSelf = weakSelf; SelectThreadViewController *strongSelf = weakSelf;
if (!strongSelf) { OWSAssert(strongSelf);
return (ContactTableViewCell *)nil;
}
// To be consistent with the threads (above), we use ContactTableViewCell // To be consistent with the threads (above), we use ContactTableViewCell
// instead of InboxTableViewCell to present contacts and threads. // instead of InboxTableViewCell to present contacts and threads.
@ -157,9 +155,7 @@ NS_ASSUME_NONNULL_BEGIN
for (SignalAccount *signalAccount in filteredSignalAccounts) { for (SignalAccount *signalAccount in filteredSignalAccounts) {
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section addItem:[OWSTableItem itemWithCustomCellBlock:^{
SelectThreadViewController *strongSelf = weakSelf; SelectThreadViewController *strongSelf = weakSelf;
if (!strongSelf) { OWSAssert(strongSelf);
return (ContactTableViewCell *)nil;
}
ContactTableViewCell *cell = [ContactTableViewCell new]; ContactTableViewCell *cell = [ContactTableViewCell new];
BOOL isBlocked = [helper isRecipientIdBlocked:signalAccount.recipientId]; BOOL isBlocked = [helper isRecipientIdBlocked:signalAccount.recipientId];

@ -103,9 +103,7 @@ NS_ASSUME_NONNULL_BEGIN
for (NSString *recipientId in [memberRecipientIds.allObjects sortedArrayUsingSelector:@selector(compare:)]) { for (NSString *recipientId in [memberRecipientIds.allObjects sortedArrayUsingSelector:@selector(compare:)]) {
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section addItem:[OWSTableItem itemWithCustomCellBlock:^{
ShowGroupMembersViewController *strongSelf = weakSelf; ShowGroupMembersViewController *strongSelf = weakSelf;
if (!strongSelf) { OWSAssert(strongSelf);
return (ContactTableViewCell *)nil;
}
ContactTableViewCell *cell = [ContactTableViewCell new]; ContactTableViewCell *cell = [ContactTableViewCell new];
SignalAccount *signalAccount = [helper signalAccountForRecipientId:recipientId]; SignalAccount *signalAccount = [helper signalAccountForRecipientId:recipientId];
@ -165,7 +163,9 @@ NS_ASSUME_NONNULL_BEGIN
fromViewController:self fromViewController:self
blockingManager:helper.blockingManager blockingManager:helper.blockingManager
contactsManager:helper.contactsManager contactsManager:helper.contactsManager
completionBlock:nil]; completionBlock:^(BOOL ignore) {
[self updateTableContents];
}];
}]]; }]];
} else { } else {
[actionSheetController [actionSheetController
@ -178,7 +178,9 @@ NS_ASSUME_NONNULL_BEGIN
fromViewController:self fromViewController:self
blockingManager:helper.blockingManager blockingManager:helper.blockingManager
contactsManager:helper.contactsManager contactsManager:helper.contactsManager
completionBlock:nil]; completionBlock:^(BOOL ignore) {
[self updateTableContents];
}];
}]]; }]];
} }
} else { } else {
@ -194,7 +196,9 @@ NS_ASSUME_NONNULL_BEGIN
fromViewController:self fromViewController:self
blockingManager:helper.blockingManager blockingManager:helper.blockingManager
contactsManager:helper.contactsManager contactsManager:helper.contactsManager
completionBlock:nil]; completionBlock:^(BOOL ignore) {
[self updateTableContents];
}];
}]]; }]];
} else { } else {
[actionSheetController [actionSheetController
@ -207,7 +211,9 @@ NS_ASSUME_NONNULL_BEGIN
fromViewController:self fromViewController:self
blockingManager:helper.blockingManager blockingManager:helper.blockingManager
contactsManager:helper.contactsManager contactsManager:helper.contactsManager
completionBlock:nil]; completionBlock:^(BOOL ignore) {
[self updateTableContents];
}];
}]]; }]];
} }
} }

@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
// non-contact account. // non-contact account.
@property (nonatomic, nullable) Contact *contact; @property (nonatomic, nullable) Contact *contact;
@property (nonatomic) BOOL isMultipleAccountContact; @property (nonatomic) BOOL hasMultipleAccountContact;
// For contacts with more than one signal account, // For contacts with more than one signal account,
// this is a label for the account. // this is a label for the account.

@ -246,9 +246,7 @@ NS_ASSUME_NONNULL_BEGIN
[section [section
addItem:[OWSTableItem itemWithCustomCellBlock:^{ addItem:[OWSTableItem itemWithCustomCellBlock:^{
UpdateGroupViewController *strongSelf = weakSelf; UpdateGroupViewController *strongSelf = weakSelf;
if (!strongSelf) { OWSAssert(strongSelf);
return (ContactTableViewCell *)nil;
}
ContactTableViewCell *cell = [ContactTableViewCell new]; ContactTableViewCell *cell = [ContactTableViewCell new];
SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId]; SignalAccount *signalAccount = [contactsViewHelper signalAccountForRecipientId:recipientId];

@ -28,6 +28,4 @@
message:(NSString *)message message:(NSString *)message
buttonLabel:(NSString *)buttonLabel; buttonLabel:(NSString *)buttonLabel;
+ (UIViewController *)topMostController;
@end @end

@ -5,6 +5,7 @@
#import "ViewControllerUtils.h" #import "ViewControllerUtils.h"
#import "Environment.h" #import "Environment.h"
#import "PhoneNumber.h" #import "PhoneNumber.h"
#import "Signal-Swift.h"
#import "SignalsViewController.h" #import "SignalsViewController.h"
#import "StringUtil.h" #import "StringUtil.h"
#import <AVFoundation/AVFoundation.h> #import <AVFoundation/AVFoundation.h>
@ -117,23 +118,11 @@ NS_ASSUME_NONNULL_BEGIN
[alert addAction:[UIAlertAction actionWithTitle:buttonLabel style:UIAlertActionStyleDefault handler:nil]]; [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; return alert;
} }
+ (UIViewController *)topMostController
{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
OWSAssert(topController);
return topController;
}
#pragma mark - Logging #pragma mark - Logging
+ (NSString *)tag + (NSString *)tag

@ -214,7 +214,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
SignalAccount *signalAccount = [[SignalAccount alloc] initWithSignalRecipient:signalRecipient]; SignalAccount *signalAccount = [[SignalAccount alloc] initWithSignalRecipient:signalRecipient];
signalAccount.contact = contact; signalAccount.contact = contact;
if (signalRecipients.count > 1) { if (signalRecipients.count > 1) {
signalAccount.isMultipleAccountContact = YES; signalAccount.hasMultipleAccountContact = YES;
signalAccount.multipleAccountLabel = signalAccount.multipleAccountLabel =
[[self class] accountLabelForContact:contact recipientId:signalRecipient.recipientId]; [[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] NSString *baseName = (signalAccount.contact ? [self displayNameForContact:signalAccount.contact]
: [self displayNameForPhoneIdentifier:signalAccount.recipientId]); : [self displayNameForPhoneIdentifier:signalAccount.recipientId]);
OWSAssert(signalAccount.isMultipleAccountContact == (signalAccount.multipleAccountLabel != nil)); OWSAssert(signalAccount.hasMultipleAccountContact == (signalAccount.multipleAccountLabel != nil));
if (signalAccount.multipleAccountLabel) { if (signalAccount.multipleAccountLabel) {
return [NSString stringWithFormat:@"%@ (%@)", baseName, signalAccount.multipleAccountLabel]; return [NSString stringWithFormat:@"%@ (%@)", baseName, signalAccount.multipleAccountLabel];
} else { } else {
@ -577,7 +577,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in
OWSAssert(font); OWSAssert(font);
NSAttributedString *baseName = [self formattedFullNameForContact:signalAccount.contact font:font]; NSAttributedString *baseName = [self formattedFullNameForContact:signalAccount.contact font:font];
OWSAssert(signalAccount.isMultipleAccountContact == (signalAccount.multipleAccountLabel != nil)); OWSAssert(signalAccount.hasMultipleAccountContact == (signalAccount.multipleAccountLabel != nil));
if (signalAccount.multipleAccountLabel) { if (signalAccount.multipleAccountLabel) {
NSMutableAttributedString *result = [NSMutableAttributedString new]; NSMutableAttributedString *result = [NSMutableAttributedString new];
[result appendAttributedString:baseName]; [result appendAttributedString:baseName];

Loading…
Cancel
Save