From 3b945a9da28b982351ec59704f3152ae8f932ea9 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 18 Oct 2017 11:53:31 -0700 Subject: [PATCH] Respond to CR. // FREEBIE --- Signal/src/ViewControllers/ContactsViewHelper.m | 3 ++- .../ConversationView/Cells/ConversationViewCell.h | 6 ++++++ .../ConversationView/Cells/OWSAudioMessageView.m | 5 +---- .../ConversationView/Cells/OWSGenericAttachmentView.m | 5 ++--- .../ConversationView/ConversationInputTextView.m | 3 ++- .../ConversationView/ConversationViewController.m | 5 +++-- .../ConversationView/ConversationViewItem.m | 9 ++++----- Signal/src/ViewControllers/CountryCodeViewController.m | 4 ++-- Signal/src/ViewControllers/NewGroupViewController.m | 4 ++-- Signal/src/ViewControllers/ProfileViewController.m | 3 ++- Signal/src/ViewControllers/RegistrationViewController.m | 4 ++-- Signal/src/ViewControllers/SelectThreadViewController.m | 4 ++-- .../src/ViewControllers/SendExternalFileViewController.m | 4 ++-- Signal/src/ViewControllers/UpdateGroupViewController.m | 7 +++---- Signal/src/contact/OWSContactsSearcher.m | 3 ++- Signal/src/environment/NotificationsManager.m | 4 ++-- 16 files changed, 39 insertions(+), 34 deletions(-) diff --git a/Signal/src/ViewControllers/ContactsViewHelper.m b/Signal/src/ViewControllers/ContactsViewHelper.m index cfdc92ba5..2d58f82bb 100644 --- a/Signal/src/ViewControllers/ContactsViewHelper.m +++ b/Signal/src/ViewControllers/ContactsViewHelper.m @@ -5,6 +5,7 @@ #import "ContactsViewHelper.h" #import "ContactTableViewCell.h" #import "Environment.h" +#import "NSString+OWS.h" #import "OWSProfileManager.h" #import "Signal-Swift.h" #import @@ -205,7 +206,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSArray *)searchTermsForSearchString:(NSString *)searchText { - return [[[searchText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] + return [[[searchText ows_stripped] componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSString *_Nullable searchTerm, NSDictionary *_Nullable bindings) { diff --git a/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h b/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h index df6695f70..6bf29fc59 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h +++ b/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h @@ -58,6 +58,12 @@ NS_ASSUME_NONNULL_BEGIN // when visible and unload when no longer visible. Non-visible cells can // cache their contents on their ConversationViewItem, but that cache may // be evacuated before the cell becomes visible again. +// +// ConversationViewController also uses this property to evacuate the cell's +// meda views when: +// +// * App enters background. +// * Users enters another view (e.g. conversation settings view, call screen, etc.). @property (nonatomic) BOOL isCellVisible; // The width of the collection view. diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m index d4120221a..04a2f1e0a 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSAudioMessageView.m @@ -231,8 +231,7 @@ NS_ASSUME_NONNULL_BEGIN if (!filename) { filename = [[self.attachmentStream filePath] lastPathComponent]; } - NSString *topText = [[filename stringByDeletingPathExtension] - stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + NSString *topText = [[filename stringByDeletingPathExtension] ows_stripped]; if (topText.length < 1) { topText = [MIMETypeUtil fileExtensionForMIMEType:self.attachmentStream.contentType].uppercaseString; } @@ -247,7 +246,6 @@ NS_ASSUME_NONNULL_BEGIN topLabel.textColor = [textColor colorWithAlphaComponent:0.85f]; topLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; topLabel.font = [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(11.f, 13.f)]; - topLabel.textAlignment = NSTextAlignmentLeft; [labelsView addSubview:topLabel]; [topLabel autoPinEdgeToSuperviewEdge:ALEdgeTop]; [topLabel autoPinWidthToSuperview]; @@ -267,7 +265,6 @@ NS_ASSUME_NONNULL_BEGIN bottomLabel.textColor = [textColor colorWithAlphaComponent:0.85f]; bottomLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; bottomLabel.font = [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(11.f, 13.f)]; - bottomLabel.textAlignment = NSTextAlignmentLeft; [labelsView addSubview:bottomLabel]; [bottomLabel autoPinWidthToSuperview]; [bottomLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:audioProgressView withOffset:kLabelVSpacing]; diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m index 97544e6b2..2c0d86910 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSGenericAttachmentView.m @@ -3,6 +3,7 @@ // #import "OWSGenericAttachmentView.h" +#import "NSString+OWS.h" #import "UIColor+JSQMessages.h" #import "UIColor+OWS.h" #import "UIFont+OWS.h" @@ -162,8 +163,7 @@ NS_ASSUME_NONNULL_BEGIN [imageView autoSetDimension:ALDimensionWidth toSize:15.f]; const CGFloat kLabelVSpacing = 2; - NSString *topText = - [self.attachmentStream.sourceFilename stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + NSString *topText = [self.attachmentStream.sourceFilename ows_stripped]; if (topText.length < 1) { topText = [MIMETypeUtil fileExtensionForMIMEType:self.attachmentStream.contentType].uppercaseString; } @@ -175,7 +175,6 @@ NS_ASSUME_NONNULL_BEGIN topLabel.textColor = textColor; topLabel.lineBreakMode = NSLineBreakByTruncatingMiddle; topLabel.font = [UIFont ows_regularFontWithSize:ScaleFromIPhone5To7Plus(13.f, 15.f)]; - topLabel.textAlignment = NSTextAlignmentLeft; [labelsView addSubview:topLabel]; [topLabel autoPinEdgeToSuperviewEdge:ALEdgeTop]; [topLabel autoPinWidthToSuperview]; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m b/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m index 10be79193..535ac1fbb 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationInputTextView.m @@ -3,6 +3,7 @@ // #import "ConversationInputTextView.h" +#import "NSString+OWS.h" #import "Signal-Swift.h" NS_ASSUME_NONNULL_BEGIN @@ -121,7 +122,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)trimmedText { - return [self.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + return [self.text ows_stripped]; } // TODO: diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 81f1af6de..b08730e04 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -20,6 +20,7 @@ #import "FingerprintViewController.h" #import "FullImageViewController.h" #import "NSAttributedString+OWS.h" +#import "NSString+OWS.h" #import "NewGroupViewController.h" #import "OWSAudioAttachmentPlayer.h" #import "OWSContactOffersCell.h" @@ -985,7 +986,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { // Only retain the cached cell media for N cells at a time. const NSInteger kCellMediaCacheWindowSize = 24; NSInteger centerRow = (firstVisibleIndexPath.row + lastVisibleIndexPath.row) / 2; - // Determine the first and law rows (inclusive) of the cached cell media load window. + // Determine the first and last rows (inclusive) of the cached cell media load window. // Note these row values may not correspond to actual rows in the collection view. // // Always retain the cached cell media for any visible cells. @@ -3698,7 +3699,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { return; } - text = [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + text = [text ows_stripped]; if (text.length < 1) { return; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m index 863dc6ffe..6ca452bc7 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m @@ -3,6 +3,7 @@ // #import "ConversationViewItem.h" +#import "NSString+OWS.h" #import "OWSAudioMessageView.h" #import "OWSContactOffersCell.h" #import "OWSMessageCell.h" @@ -274,14 +275,12 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) if (!displayableText) { // Only show up to 2kb of text. const NSUInteger kMaxTextDisplayLength = 2 * 1024; - text = [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + text = [text ows_stripped]; displayableText = [[DisplayableTextFilter new] displayableText:text]; if (displayableText.length > kMaxTextDisplayLength) { // Trim whitespace before _AND_ after slicing the snipper from the string. - NSString *snippet = - [[[displayableText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] - substringWithRange:NSMakeRange(0, kMaxTextDisplayLength)] - stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *snippet = [ + [[displayableText ows_stripped] substringWithRange:NSMakeRange(0, kMaxTextDisplayLength)] ows_stripped]; displayableText = [NSString stringWithFormat:NSLocalizedString(@"OVERSIZE_TEXT_DISPLAY_FORMAT", @"A display format for oversize text messages."), snippet]; diff --git a/Signal/src/ViewControllers/CountryCodeViewController.m b/Signal/src/ViewControllers/CountryCodeViewController.m index 94771136b..c202436cb 100644 --- a/Signal/src/ViewControllers/CountryCodeViewController.m +++ b/Signal/src/ViewControllers/CountryCodeViewController.m @@ -3,6 +3,7 @@ // #import "CountryCodeViewController.h" +#import "NSString+OWS.h" #import "PhoneNumberUtil.h" #import "UIColor+OWS.h" #import "UIFont+OWS.h" @@ -142,8 +143,7 @@ - (void)searchTextDidChange { - NSString *searchText = - [self.searchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *searchText = [self.searchBar.text ows_stripped]; self.countryCodes = [PhoneNumberUtil countryCodesForSearchTerm:searchText]; diff --git a/Signal/src/ViewControllers/NewGroupViewController.m b/Signal/src/ViewControllers/NewGroupViewController.m index 7e8d9babf..9ff7b3729 100644 --- a/Signal/src/ViewControllers/NewGroupViewController.m +++ b/Signal/src/ViewControllers/NewGroupViewController.m @@ -9,6 +9,7 @@ #import "ContactTableViewCell.h" #import "ContactsViewHelper.h" #import "Environment.h" +#import "NSString+OWS.h" #import "OWSContactsManager.h" #import "OWSNavigationController.h" #import "OWSTableViewController.h" @@ -515,8 +516,7 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; - (TSGroupModel *)makeGroup { - NSString *groupName = [self.groupNameTextField.text - stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *groupName = [self.groupNameTextField.text ows_stripped]; NSMutableArray *recipientIds = [self.memberRecipientIds.allObjects mutableCopy]; [recipientIds addObject:[self.contactsViewHelper localNumber]]; NSData *groupId = [SecurityUtils generateRandomBytes:16]; diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 4804e9625..cda6d75a9 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -6,6 +6,7 @@ #import "AppDelegate.h" #import "AvatarViewHelper.h" #import "HomeViewController.h" +#import "NSString+OWS.h" #import "OWSNavigationController.h" #import "OWSProfileManager.h" #import "Signal-Swift.h" @@ -410,7 +411,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat - (NSString *)normalizedProfileName { - return [self.nameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + return [self.nameTextField.text ows_stripped]; } - (void)updateProfileCompleted diff --git a/Signal/src/ViewControllers/RegistrationViewController.m b/Signal/src/ViewControllers/RegistrationViewController.m index e86d64079..86eb0409d 100644 --- a/Signal/src/ViewControllers/RegistrationViewController.m +++ b/Signal/src/ViewControllers/RegistrationViewController.m @@ -6,6 +6,7 @@ #import "CodeVerificationViewController.h" #import "CountryCodeViewController.h" #import "Environment.h" +#import "NSString+OWS.h" #import "PhoneNumber.h" #import "PhoneNumberUtil.h" #import "Signal-Swift.h" @@ -280,8 +281,7 @@ NSString *const kKeychainKey_LastRegisteredPhoneNumber = @"kKeychainKey_LastRegi - (void)sendCodeAction { - NSString *phoneNumberText = - [_phoneNumberTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *phoneNumberText = [_phoneNumberTextField.text ows_stripped]; if (phoneNumberText.length < 1) { [OWSAlerts showAlertWithTitle:NSLocalizedString(@"REGISTRATION_VIEW_NO_PHONE_NUMBER_ALERT_TITLE", diff --git a/Signal/src/ViewControllers/SelectThreadViewController.m b/Signal/src/ViewControllers/SelectThreadViewController.m index 268ffc1ca..a16fb5df5 100644 --- a/Signal/src/ViewControllers/SelectThreadViewController.m +++ b/Signal/src/ViewControllers/SelectThreadViewController.m @@ -7,6 +7,7 @@ #import "ContactTableViewCell.h" #import "ContactsViewHelper.h" #import "Environment.h" +#import "NSString+OWS.h" #import "OWSContactsManager.h" #import "OWSContactsSearcher.h" #import "OWSTableViewController.h" @@ -223,8 +224,7 @@ NS_ASSUME_NONNULL_BEGIN { NSArray *threads = self.threadViewHelper.threads; - NSString *searchTerm = - [[self.searchBar text] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *searchTerm = [[self.searchBar text] ows_stripped]; if ([searchTerm isEqualToString:@""]) { return threads; diff --git a/Signal/src/ViewControllers/SendExternalFileViewController.m b/Signal/src/ViewControllers/SendExternalFileViewController.m index ad31813b8..264a18539 100644 --- a/Signal/src/ViewControllers/SendExternalFileViewController.m +++ b/Signal/src/ViewControllers/SendExternalFileViewController.m @@ -4,6 +4,7 @@ #import "SendExternalFileViewController.h" #import "Environment.h" +#import "NSString+OWS.h" #import "Signal-Swift.h" #import "ThreadUtil.h" #import "UIColor+OWS.h" @@ -141,8 +142,7 @@ NS_ASSUME_NONNULL_BEGIN // TODO: If we reuse this VC, for example to offer a "forward attachment to other thread", // feature, this assumption would no longer apply. OWSAssert(self.attachment); - NSString *filename = - [self.attachment.sourceFilename stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; + NSString *filename = [self.attachment.sourceFilename ows_stripped]; OWSAssert(filename.length > 0); const NSUInteger kMaxFilenameLength = 20; if (filename.length > kMaxFilenameLength) { diff --git a/Signal/src/ViewControllers/UpdateGroupViewController.m b/Signal/src/ViewControllers/UpdateGroupViewController.m index eaced2e56..63471c2d0 100644 --- a/Signal/src/ViewControllers/UpdateGroupViewController.m +++ b/Signal/src/ViewControllers/UpdateGroupViewController.m @@ -9,6 +9,7 @@ #import "ContactTableViewCell.h" #import "ContactsViewHelper.h" #import "Environment.h" +#import "NSString+OWS.h" #import "OWSContactsManager.h" #import "OWSNavigationController.h" #import "OWSTableViewController.h" @@ -196,8 +197,7 @@ NS_ASSUME_NONNULL_BEGIN UITextField *groupNameTextField = [UITextField new]; _groupNameTextField = groupNameTextField; - self.groupNameTextField.text = [self.thread.groupModel.groupName - stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + self.groupNameTextField.text = [self.thread.groupModel.groupName ows_stripped]; groupNameTextField.textColor = [UIColor blackColor]; groupNameTextField.font = [UIFont ows_dynamicTypeTitle2Font]; groupNameTextField.placeholder @@ -373,8 +373,7 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert(self.conversationSettingsViewDelegate); - NSString *groupName = [self.groupNameTextField.text - stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *groupName = [self.groupNameTextField.text ows_stripped]; TSGroupModel *groupModel = [[TSGroupModel alloc] initWithTitle:groupName memberIds:[self.memberRecipientIds.allObjects mutableCopy] image:self.groupAvatar diff --git a/Signal/src/contact/OWSContactsSearcher.m b/Signal/src/contact/OWSContactsSearcher.m index f776e444d..774f1038c 100644 --- a/Signal/src/contact/OWSContactsSearcher.m +++ b/Signal/src/contact/OWSContactsSearcher.m @@ -3,6 +3,7 @@ // #import "OWSContactsSearcher.h" +#import "NSString+OWS.h" #import @interface OWSContactsSearcher () @@ -22,7 +23,7 @@ } - (NSArray *)filterWithString:(NSString *)string { - NSString *searchTerm = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *searchTerm = [string ows_stripped]; if ([searchTerm isEqualToString:@""]) { return self.contacts; diff --git a/Signal/src/environment/NotificationsManager.m b/Signal/src/environment/NotificationsManager.m index 30a9ad50e..e5315b0f8 100644 --- a/Signal/src/environment/NotificationsManager.m +++ b/Signal/src/environment/NotificationsManager.m @@ -4,6 +4,7 @@ #import "NotificationsManager.h" #import "Environment.h" +#import "NSString+OWS.h" #import "OWSContactsManager.h" #import "OWSPreferences.h" #import "PushManager.h" @@ -272,8 +273,7 @@ NSString *const kNotificationsManagerNewMesssageSoundName = @"NewMessage.aifc"; BOOL shouldPlaySound = [self shouldPlaySoundForNotification]; NSString *senderName = [contactsManager displayNameForPhoneIdentifier:message.authorId]; - NSString *groupName = - [thread.name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *groupName = [thread.name ows_stripped]; if (groupName.length < 1) { groupName = [MessageStrings newGroupDefaultTitle]; }