diff --git a/Signal/src/Storyboard/Main.storyboard b/Signal/src/Storyboard/Main.storyboard index 2459c564b..20cdd4598 100644 --- a/Signal/src/Storyboard/Main.storyboard +++ b/Signal/src/Storyboard/Main.storyboard @@ -479,7 +479,7 @@ - + @@ -535,13 +535,13 @@ - + @@ -550,7 +550,7 @@ - + @@ -566,7 +566,7 @@ - + diff --git a/Signal/src/ViewControllers/AddToBlockListViewController.m b/Signal/src/ViewControllers/AddToBlockListViewController.m index 557cff5bb..27e25fd2e 100644 --- a/Signal/src/ViewControllers/AddToBlockListViewController.m +++ b/Signal/src/ViewControllers/AddToBlockListViewController.m @@ -281,7 +281,7 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI contactsManager:_contactsManager completionBlock:^(BOOL isBlocked) { if (isBlocked) { - // Clear phone number text field is block succeeds. + // Clear phone number text field if block succeeds. weakSelf.phoneNumberTextField.text = nil; [weakSelf.navigationController popViewControllerAnimated:YES]; } diff --git a/Signal/src/ViewControllers/BlockListUIUtils.h b/Signal/src/ViewControllers/BlockListUIUtils.h index c26ca1c61..f1cf0671c 100644 --- a/Signal/src/ViewControllers/BlockListUIUtils.h +++ b/Signal/src/ViewControllers/BlockListUIUtils.h @@ -4,6 +4,8 @@ #import +NS_ASSUME_NONNULL_BEGIN + @class Contact; @class OWSBlockingManager; @class OWSContactsManager; @@ -18,18 +20,20 @@ typedef void (^BlockActionCompletionBlock)(BOOL isBlocked); fromViewController:(UIViewController *)fromViewController blockingManager:(OWSBlockingManager *)blockingManager contactsManager:(OWSContactsManager *)contactsManager - completionBlock:(BlockActionCompletionBlock)completionBlock; + completionBlock:(nullable BlockActionCompletionBlock)completionBlock; + (void)showBlockPhoneNumberActionSheet:(NSString *)phoneNumber fromViewController:(UIViewController *)fromViewController blockingManager:(OWSBlockingManager *)blockingManager contactsManager:(OWSContactsManager *)contactsManager - completionBlock:(BlockActionCompletionBlock)completionBlock; + completionBlock:(nullable BlockActionCompletionBlock)completionBlock; + (void)showUnblockPhoneNumberActionSheet:(NSString *)phoneNumber fromViewController:(UIViewController *)fromViewController blockingManager:(OWSBlockingManager *)blockingManager contactsManager:(OWSContactsManager *)contactsManager - completionBlock:(BlockActionCompletionBlock)completionBlock; + completionBlock:(nullable BlockActionCompletionBlock)completionBlock; @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/BlockListUIUtils.m b/Signal/src/ViewControllers/BlockListUIUtils.m index 1200aa0df..1af210bf0 100644 --- a/Signal/src/ViewControllers/BlockListUIUtils.m +++ b/Signal/src/ViewControllers/BlockListUIUtils.m @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN fromViewController:(UIViewController *)fromViewController blockingManager:(OWSBlockingManager *)blockingManager contactsManager:(OWSContactsManager *)contactsManager - completionBlock:(BlockActionCompletionBlock)completionBlock + completionBlock:(nullable BlockActionCompletionBlock)completionBlock { NSMutableArray *phoneNumbers = [NSMutableArray new]; for (PhoneNumber *phoneNumber in contact.parsedPhoneNumbers) { @@ -25,6 +25,8 @@ NS_ASSUME_NONNULL_BEGIN } } if (phoneNumbers.count < 1) { + DDLogError(@"%@ Contact has no phone numbers", self.tag); + OWSAssert(0); [self showBlockFailedAlert:fromViewController]; if (completionBlock) { completionBlock(NO); @@ -43,7 +45,7 @@ NS_ASSUME_NONNULL_BEGIN fromViewController:(UIViewController *)fromViewController blockingManager:(OWSBlockingManager *)blockingManager contactsManager:(OWSContactsManager *)contactsManager - completionBlock:(BlockActionCompletionBlock)completionBlock + completionBlock:(nullable BlockActionCompletionBlock)completionBlock { NSString *displayName = [contactsManager displayNameForPhoneIdentifier:phoneNumber]; [self showBlockPhoneNumbersActionSheet:@[ phoneNumber ] @@ -57,7 +59,7 @@ NS_ASSUME_NONNULL_BEGIN displayName:(NSString *)displayName fromViewController:(UIViewController *)fromViewController blockingManager:(OWSBlockingManager *)blockingManager - completionBlock:(BlockActionCompletionBlock)completionBlock + completionBlock:(nullable BlockActionCompletionBlock)completionBlock { OWSAssert(phoneNumbers.count > 0); OWSAssert(displayName.length > 0); @@ -67,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN NSString *title = [NSString stringWithFormat:NSLocalizedString(@"BLOCK_LIST_BLOCK_TITLE_FORMAT", @"A format for the 'block user' action sheet title. Embeds {{the " @"blocked user's name or phone number}}."), - displayName]; + [self formatDisplayNameForAlertTitle:displayName]]; UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet]; @@ -119,7 +121,7 @@ NS_ASSUME_NONNULL_BEGIN stringWithFormat:NSLocalizedString(@"BLOCK_LIST_VIEW_BLOCKED_ALERT_MESSAGE_FORMAT", @"The message format of the 'user blocked' " @"alert. Embeds {{the blocked user's name or phone number}}."), - displayName] + [self formatDisplayNameForAlertMessage:displayName]] fromViewController:fromViewController]; } @@ -127,18 +129,19 @@ NS_ASSUME_NONNULL_BEGIN fromViewController:(UIViewController *)fromViewController blockingManager:(OWSBlockingManager *)blockingManager contactsManager:(OWSContactsManager *)contactsManager - completionBlock:(BlockActionCompletionBlock)completionBlock + completionBlock:(nullable BlockActionCompletionBlock)completionBlock { OWSAssert(phoneNumber.length > 0); OWSAssert(fromViewController); OWSAssert(blockingManager); + OWSAssert(contactsManager); NSString *displayName = [contactsManager displayNameForPhoneIdentifier:phoneNumber]; NSString *title = [NSString stringWithFormat:NSLocalizedString(@"BLOCK_LIST_UNBLOCK_TITLE_FORMAT", @"A format for the 'unblock user' action sheet title. Embeds " @"{{the blocked user's name or phone number}}."), - displayName]; + [self formatDisplayNameForAlertTitle:displayName]]; UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet]; @@ -187,7 +190,7 @@ NS_ASSUME_NONNULL_BEGIN stringWithFormat:NSLocalizedString(@"BLOCK_LIST_VIEW_UNBLOCKED_ALERT_MESSAGE_FORMAT", @"The message format of the 'user unblocked' " @"alert. Embeds {{the blocked user's name or phone number}}."), - displayName] + [self formatDisplayNameForAlertMessage:displayName]] fromViewController:fromViewController]; } @@ -230,6 +233,27 @@ NS_ASSUME_NONNULL_BEGIN [fromViewController presentViewController:controller animated:YES completion:nil]; } ++ (NSString *)formatDisplayNameForAlertTitle:(NSString *)displayName +{ + return [self formatDisplayName:displayName withMaxLength:20]; +} + ++ (NSString *)formatDisplayNameForAlertMessage:(NSString *)displayName +{ + return [self formatDisplayName:displayName withMaxLength:127]; +} + ++ (NSString *)formatDisplayName:(NSString *)displayName withMaxLength:(NSUInteger)maxLength +{ + OWSAssert(displayName.length > 0); + + if (displayName.length > maxLength) { + return [[displayName substringToIndex:maxLength] stringByAppendingString:@"…"]; + } + + return displayName; +} + #pragma mark - Logging + (NSString *)tag diff --git a/Signal/src/ViewControllers/BlockListViewController.m b/Signal/src/ViewControllers/BlockListViewController.m index fd43f0e35..c99be8eda 100644 --- a/Signal/src/ViewControllers/BlockListViewController.m +++ b/Signal/src/ViewControllers/BlockListViewController.m @@ -159,7 +159,6 @@ typedef NS_ENUM(NSInteger, BlockListViewControllerSection) { [BlockListUIUtils showUnblockPhoneNumberActionSheet:phoneNumber fromViewController:self blockingManager:_blockingManager - contactsManager:_contactsManager completionBlock:nil]; break; diff --git a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m index 1a5beb489..4e20836da 100644 --- a/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m +++ b/Signal/src/ViewControllers/OWSConversationSettingsTableViewController.m @@ -426,6 +426,7 @@ static NSString *const OWSConversationSettingsTableViewControllerSegueShowGroupM if (![sender isKindOfClass:[UISwitch class]]) { DDLogError(@"%@ Unexpected sender for block user switch: %@", self.tag, sender); + OWSAssert(0); } UISwitch *blockUserSwitch = (UISwitch *)sender; diff --git a/Signal/src/ViewControllers/OWSTableViewController.h b/Signal/src/ViewControllers/OWSTableViewController.h index 2fb2b47a0..02c0e3a3f 100644 --- a/Signal/src/ViewControllers/OWSTableViewController.h +++ b/Signal/src/ViewControllers/OWSTableViewController.h @@ -41,18 +41,18 @@ typedef UITableViewCell * (^OWSTableCustomCellBlock)(); @interface OWSTableItem : NSObject -+ (OWSTableItem *)itemWithTitle:(NSString *)title actionBlock:(OWSTableActionBlock)actionBlock; ++ (OWSTableItem *)itemWithTitle:(NSString *)title actionBlock:(nullable OWSTableActionBlock)actionBlock; + (OWSTableItem *)itemWithCustomCell:(UITableViewCell *)customCell customRowHeight:(CGFloat)customRowHeight - actionBlock:(OWSTableActionBlock)actionBlock; + actionBlock:(nullable OWSTableActionBlock)actionBlock; + (OWSTableItem *)itemWithCustomCellBlock:(OWSTableCustomCellBlock)customCellBlock customRowHeight:(CGFloat)customRowHeight - actionBlock:(OWSTableActionBlock)actionBlock; + actionBlock:(nullable OWSTableActionBlock)actionBlock; + (OWSTableItem *)itemWithCustomCellBlock:(OWSTableCustomCellBlock)customCellBlock - actionBlock:(OWSTableActionBlock)actionBlock; + actionBlock:(nullable OWSTableActionBlock)actionBlock; - (UITableViewCell *)customCell; - (NSNumber *)customRowHeight; diff --git a/Signal/src/ViewControllers/OWSTableViewController.m b/Signal/src/ViewControllers/OWSTableViewController.m index 7c66ca72f..c52de24e0 100644 --- a/Signal/src/ViewControllers/OWSTableViewController.m +++ b/Signal/src/ViewControllers/OWSTableViewController.m @@ -88,7 +88,7 @@ NS_ASSUME_NONNULL_BEGIN @implementation OWSTableItem -+ (OWSTableItem *)itemWithTitle:(NSString *)title actionBlock:(OWSTableActionBlock)actionBlock ++ (OWSTableItem *)itemWithTitle:(NSString *)title actionBlock:(nullable OWSTableActionBlock)actionBlock { OWSAssert(title.length > 0); @@ -101,7 +101,7 @@ NS_ASSUME_NONNULL_BEGIN + (OWSTableItem *)itemWithCustomCell:(UITableViewCell *)customCell customRowHeight:(CGFloat)customRowHeight - actionBlock:(OWSTableActionBlock)actionBlock + actionBlock:(nullable OWSTableActionBlock)actionBlock { OWSAssert(customCell); OWSAssert(customRowHeight > 0); @@ -116,7 +116,7 @@ NS_ASSUME_NONNULL_BEGIN + (OWSTableItem *)itemWithCustomCellBlock:(OWSTableCustomCellBlock)customCellBlock customRowHeight:(CGFloat)customRowHeight - actionBlock:(OWSTableActionBlock)actionBlock + actionBlock:(nullable OWSTableActionBlock)actionBlock { OWSAssert(customCellBlock); OWSAssert(customRowHeight > 0); @@ -130,7 +130,7 @@ NS_ASSUME_NONNULL_BEGIN } + (OWSTableItem *)itemWithCustomCellBlock:(OWSTableCustomCellBlock)customCellBlock - actionBlock:(OWSTableActionBlock)actionBlock + actionBlock:(nullable OWSTableActionBlock)actionBlock { OWSAssert(customCellBlock);