From d3c2f44aeb5bff803a8f52caf457df0f4d5074aa Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Sun, 13 Nov 2016 13:30:22 -0500 Subject: [PATCH] Exclude extra data detectors. Data detectors work by matching local text against a series of local matchers. No network activity is required. Some of the data detectors are really useful (e.g. a link, or being able to copy a phone number). Some aren't very useful, e.g. pop culture references, and seeing things underlined is giving people the false impression that their data is being inspected remotely. // FREEBIE --- Signal.xcodeproj/project.pbxproj | 6 ++++ .../view controllers/MessagesViewController.m | 30 +++++++++--------- .../views/JSQMessagesCollectionViewCell+OWS.h | 14 +++++++++ .../views/JSQMessagesCollectionViewCell+OWS.m | 31 +++++++++++++++++++ .../OWSIncomingMessageCollectionViewCell.h | 1 + .../OWSIncomingMessageCollectionViewCell.m | 1 + .../OWSOutgoingMessageCollectionViewCell.h | 1 + .../OWSOutgoingMessageCollectionViewCell.m | 5 +++ 8 files changed, 74 insertions(+), 15 deletions(-) create mode 100644 Signal/src/views/JSQMessagesCollectionViewCell+OWS.h create mode 100644 Signal/src/views/JSQMessagesCollectionViewCell+OWS.m diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index a46d7480d..fc6e8e6d5 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 452D1EE81DCA90D100A57EC4 /* MesssagesBubblesSizeCalculatorTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 452D1EE71DCA90D100A57EC4 /* MesssagesBubblesSizeCalculatorTest.swift */; }; 452E3C8E1D935C77002A45B0 /* OWSConversationSettingsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 452E3C8D1D935C77002A45B0 /* OWSConversationSettingsTableViewController.m */; }; 452E3C8F1D935C77002A45B0 /* OWSConversationSettingsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 452E3C8D1D935C77002A45B0 /* OWSConversationSettingsTableViewController.m */; }; + 4531C9C41DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 4531C9C31DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m */; }; 453D28B71D32BA5F00D523F0 /* OWSDisplayedMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B61D32BA5F00D523F0 /* OWSDisplayedMessage.m */; }; 453D28BA1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */; }; 453D28BB1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */; }; @@ -554,6 +555,8 @@ 452D1EE71DCA90D100A57EC4 /* MesssagesBubblesSizeCalculatorTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MesssagesBubblesSizeCalculatorTest.swift; path = Models/MesssagesBubblesSizeCalculatorTest.swift; sourceTree = ""; }; 452E3C8C1D935C77002A45B0 /* OWSConversationSettingsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSConversationSettingsTableViewController.h; sourceTree = ""; }; 452E3C8D1D935C77002A45B0 /* OWSConversationSettingsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = OWSConversationSettingsTableViewController.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + 4531C9C21DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JSQMessagesCollectionViewCell+OWS.h"; sourceTree = ""; }; + 4531C9C31DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSQMessagesCollectionViewCell+OWS.m"; sourceTree = ""; }; 453CC0361D08E1A60040EBA3 /* sn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sn; path = translations/sn.lproj/Localizable.strings; sourceTree = ""; }; 453D28B51D32BA5F00D523F0 /* OWSDisplayedMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSDisplayedMessage.h; sourceTree = ""; }; 453D28B61D32BA5F00D523F0 /* OWSDisplayedMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSDisplayedMessage.m; sourceTree = ""; }; @@ -1850,6 +1853,8 @@ 450873C11D9D5149006B54F2 /* OWSExpirationTimerView.h */, 450873C21D9D5149006B54F2 /* OWSExpirationTimerView.m */, 450873C91D9D86F4006B54F2 /* OWSExpirableMessageView.h */, + 4531C9C21DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.h */, + 4531C9C31DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m */, ); name = Views; path = views; @@ -2827,6 +2832,7 @@ B97940271832BD2400BD66CB /* UIUtil.m in Sources */, 4CE0E3771B954546007210CF /* TSAnimatedAdapter.m in Sources */, 76EB05BE18170B33006006FC /* ConfirmPacket.m in Sources */, + 4531C9C41DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m in Sources */, 4516E3FF1DD2193B00DC4206 /* OWS101ExistingUsersBlockOnIdentityChange.m in Sources */, 76EB05A818170B33006006FC /* RtpSocket.m in Sources */, E197B61818BBEC1A00F073E5 /* RemoteIOAudio.m in Sources */, diff --git a/Signal/src/view controllers/MessagesViewController.m b/Signal/src/view controllers/MessagesViewController.m index 8d955402b..5a3391e0c 100644 --- a/Signal/src/view controllers/MessagesViewController.m +++ b/Signal/src/view controllers/MessagesViewController.m @@ -788,16 +788,15 @@ typedef enum : NSUInteger { - (JSQMessagesCollectionViewCell *)loadIncomingMessageCellForMessage:(id)message atIndexPath:(NSIndexPath *)indexPath { - JSQMessagesCollectionViewCell *cell = - (JSQMessagesCollectionViewCell *)[super collectionView:self.collectionView cellForItemAtIndexPath:indexPath]; - if (!message.isMediaMessage) { - cell.textView.textColor = [UIColor ows_blackColor]; - cell.textView.linkTextAttributes = @{ - NSForegroundColorAttributeName : cell.textView.textColor, - NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle | NSUnderlinePatternSolid) - }; - } + OWSIncomingMessageCollectionViewCell *cell + = (OWSIncomingMessageCollectionViewCell *)[super collectionView:self.collectionView + cellForItemAtIndexPath:indexPath]; + if (![cell isKindOfClass:[OWSIncomingMessageCollectionViewCell class]]) { + DDLogError(@"%@ Unexpected cell type: %@", self.tag, cell); + return cell; + } + [cell ows_didLoad]; return cell; } @@ -808,19 +807,20 @@ typedef enum : NSUInteger { = (OWSOutgoingMessageCollectionViewCell *)[super collectionView:self.collectionView cellForItemAtIndexPath:indexPath]; + if (![cell isKindOfClass:[OWSOutgoingMessageCollectionViewCell class]]) { + DDLogError(@"%@ Unexpected cell type: %@", self.tag, cell); + return cell; + } + [cell ows_didLoad]; + if (message.isMediaMessage) { if (![message isKindOfClass:[TSMessageAdapter class]]) { DDLogError(@"%@ Unexpected media message:%@", self.tag, message.class); } TSMessageAdapter *messageAdapter = (TSMessageAdapter *)message; cell.mediaView.alpha = messageAdapter.mediaViewAlpha; - } else { - cell.textView.textColor = [UIColor whiteColor]; - cell.textView.linkTextAttributes = @{ - NSForegroundColorAttributeName : cell.textView.textColor, - NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle | NSUnderlinePatternSolid) - }; } + return cell; } diff --git a/Signal/src/views/JSQMessagesCollectionViewCell+OWS.h b/Signal/src/views/JSQMessagesCollectionViewCell+OWS.h new file mode 100644 index 000000000..2d8d737c6 --- /dev/null +++ b/Signal/src/views/JSQMessagesCollectionViewCell+OWS.h @@ -0,0 +1,14 @@ +// Created by Michael Kirk on 11/13/16. +// Copyright © 2016 Open Whisper Systems. All rights reserved. + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface JSQMessagesCollectionViewCell (OWS) + +- (void)ows_didLoad; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/views/JSQMessagesCollectionViewCell+OWS.m b/Signal/src/views/JSQMessagesCollectionViewCell+OWS.m new file mode 100644 index 000000000..1ce7b9e0c --- /dev/null +++ b/Signal/src/views/JSQMessagesCollectionViewCell+OWS.m @@ -0,0 +1,31 @@ +// Created by Michael Kirk on 11/13/16. +// Copyright © 2016 Open Whisper Systems. All rights reserved. + +#import "JSQMessagesCollectionViewCell+OWS.h" +#import "UIColor+OWS.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation JSQMessagesCollectionViewCell (OWS) + +- (UIColor *)ows_textColor +{ + return [UIColor ows_blackColor]; +} + +- (void)ows_didLoad +{ + self.textView.textColor = self.ows_textColor; + self.textView.linkTextAttributes = @{ + NSForegroundColorAttributeName : self.ows_textColor, + NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle | NSUnderlinePatternSolid) + }; + + self.textView.dataDetectorTypes + = (UIDataDetectorTypePhoneNumber | UIDataDetectorTypeLink | UIDataDetectorTypeAddress + | UIDataDetectorTypeCalendarEvent); +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/views/OWSIncomingMessageCollectionViewCell.h b/Signal/src/views/OWSIncomingMessageCollectionViewCell.h index 848669628..022b9eeb5 100644 --- a/Signal/src/views/OWSIncomingMessageCollectionViewCell.h +++ b/Signal/src/views/OWSIncomingMessageCollectionViewCell.h @@ -1,6 +1,7 @@ // Created by Michael Kirk on 9/29/16. // Copyright © 2016 Open Whisper Systems. All rights reserved. +#import "JSQMessagesCollectionViewCell+OWS.h" #import "OWSExpirableMessageView.h" #import diff --git a/Signal/src/views/OWSIncomingMessageCollectionViewCell.m b/Signal/src/views/OWSIncomingMessageCollectionViewCell.m index 7a9157051..88c370f9a 100644 --- a/Signal/src/views/OWSIncomingMessageCollectionViewCell.m +++ b/Signal/src/views/OWSIncomingMessageCollectionViewCell.m @@ -3,6 +3,7 @@ #import "OWSIncomingMessageCollectionViewCell.h" #import "OWSExpirationTimerView.h" +#import "UIColor+OWS.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Signal/src/views/OWSOutgoingMessageCollectionViewCell.h b/Signal/src/views/OWSOutgoingMessageCollectionViewCell.h index 16ce98ce6..6423b7772 100644 --- a/Signal/src/views/OWSOutgoingMessageCollectionViewCell.h +++ b/Signal/src/views/OWSOutgoingMessageCollectionViewCell.h @@ -1,6 +1,7 @@ // Created by Michael Kirk on 9/28/16. // Copyright © 2016 Open Whisper Systems. All rights reserved. +#import "JSQMessagesCollectionViewCell+OWS.h" #import "OWSExpirableMessageView.h" #import diff --git a/Signal/src/views/OWSOutgoingMessageCollectionViewCell.m b/Signal/src/views/OWSOutgoingMessageCollectionViewCell.m index 06f924d51..ed304e759 100644 --- a/Signal/src/views/OWSOutgoingMessageCollectionViewCell.m +++ b/Signal/src/views/OWSOutgoingMessageCollectionViewCell.m @@ -28,6 +28,11 @@ NS_ASSUME_NONNULL_BEGIN self.expirationTimerViewWidthConstraint.constant = 0.0f; } +- (UIColor *)ows_textColor +{ + return [UIColor whiteColor]; +} + // pragma mark - OWSExpirableMessageView - (void)startExpirationTimerWithExpiresAtSeconds:(uint64_t)expiresAtSeconds