From e75ed5e477ddab9098f1f89d699b07b3e4ab6067 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 26 Apr 2017 12:25:41 -0400 Subject: [PATCH] Respond to CR. // FREEBIE --- .../TSMessageAdapaters/TSAnimatedAdapter.m | 4 +-- .../ViewControllers/MessagesViewController.m | 9 ++++--- .../SelectThreadViewController.h | 4 +++ .../SelectThreadViewController.m | 15 ----------- .../SendExternalFileViewController.h | 4 +++ .../SendExternalFileViewController.m | 26 +++++-------------- .../ViewControllers/SignalAttachment.swift | 2 +- Signal/src/ViewControllers/ThreadViewHelper.h | 6 ++++- Signal/src/ViewControllers/ThreadViewHelper.m | 2 +- 9 files changed, 29 insertions(+), 43 deletions(-) diff --git a/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m b/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m index d1617ce51..109a18c29 100644 --- a/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m +++ b/Signal/src/Models/TSMessageAdapaters/TSAnimatedAdapter.m @@ -131,8 +131,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)performEditingAction:(SEL)action { if (action == @selector(copy:)) { - UIPasteboard *pasteBoard = UIPasteboard.generalPasteboard; - [pasteBoard setData:self.fileData forPasteboardType:(__bridge NSString *)kUTTypeGIF]; + UIPasteboard *pasteboard = UIPasteboard.generalPasteboard; + [pasteboard setData:self.fileData forPasteboardType:(__bridge NSString *)kUTTypeGIF]; } else if (action == NSSelectorFromString(@"save:")) { NSData *photoData = self.fileData; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; diff --git a/Signal/src/ViewControllers/MessagesViewController.m b/Signal/src/ViewControllers/MessagesViewController.m index 4a8571102..39dfe7f67 100644 --- a/Signal/src/ViewControllers/MessagesViewController.m +++ b/Signal/src/ViewControllers/MessagesViewController.m @@ -113,15 +113,16 @@ typedef enum : NSUInteger { return YES; } -- (BOOL)pasteBoardHasPossibleAttachment { +- (BOOL)pasteboardHasPossibleAttachment +{ // We don't want to load/convert images more than once so we // only do a cursory validation pass at this time. - return ([SignalAttachment pasteboardHasPossibleAttachment] && ![SignalAttachment pasteBoardHasText]); + return ([SignalAttachment pasteboardHasPossibleAttachment] && ![SignalAttachment pasteboardHasText]); } - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(paste:)) { - if ([self pasteBoardHasPossibleAttachment]) { + if ([self pasteboardHasPossibleAttachment]) { return YES; } } @@ -129,7 +130,7 @@ typedef enum : NSUInteger { } - (void)paste:(id)sender { - if ([self pasteBoardHasPossibleAttachment]) { + if ([self pasteboardHasPossibleAttachment]) { SignalAttachment *attachment = [SignalAttachment attachmentFromPasteboard]; // Note: attachment might be nil or have an error at this point; that's fine. [self.textViewPasteDelegate didPasteAttachment:attachment]; diff --git a/Signal/src/ViewControllers/SelectThreadViewController.h b/Signal/src/ViewControllers/SelectThreadViewController.h index dc812826e..089f377b2 100644 --- a/Signal/src/ViewControllers/SelectThreadViewController.h +++ b/Signal/src/ViewControllers/SelectThreadViewController.h @@ -4,6 +4,8 @@ @class TSThread; +NS_ASSUME_NONNULL_BEGIN + @protocol SelectThreadViewControllerDelegate - (void)threadWasSelected:(TSThread *)thread; @@ -19,3 +21,5 @@ @property (nonatomic, weak) id delegate; @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/SelectThreadViewController.m b/Signal/src/ViewControllers/SelectThreadViewController.m index 8ad82ff6a..471b8f820 100644 --- a/Signal/src/ViewControllers/SelectThreadViewController.m +++ b/Signal/src/ViewControllers/SelectThreadViewController.m @@ -360,21 +360,6 @@ NS_ASSUME_NONNULL_BEGIN return YES; } - if ([self isCurrentUserContact:contact]) { - return YES; - } - - return NO; -} - -- (BOOL)isCurrentUserContact:(Contact *)contact -{ - for (PhoneNumber *phoneNumber in contact.parsedPhoneNumbers) { - if ([[phoneNumber toE164] isEqualToString:[TSAccountManager localNumber]]) { - return YES; - } - } - return NO; } diff --git a/Signal/src/ViewControllers/SendExternalFileViewController.h b/Signal/src/ViewControllers/SendExternalFileViewController.h index b0c04f44d..45f58c895 100644 --- a/Signal/src/ViewControllers/SendExternalFileViewController.h +++ b/Signal/src/ViewControllers/SendExternalFileViewController.h @@ -4,6 +4,8 @@ #import "SelectThreadViewController.h" +NS_ASSUME_NONNULL_BEGIN + @class SignalAttachment; @interface SendExternalFileViewController : SelectThreadViewController @@ -11,3 +13,5 @@ @property (nonatomic) SignalAttachment *attachment; @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/SendExternalFileViewController.m b/Signal/src/ViewControllers/SendExternalFileViewController.m index 19ad05022..f2cd236d8 100644 --- a/Signal/src/ViewControllers/SendExternalFileViewController.m +++ b/Signal/src/ViewControllers/SendExternalFileViewController.m @@ -9,12 +9,16 @@ #import #import +NS_ASSUME_NONNULL_BEGIN + @interface SendExternalFileViewController () @property (nonatomic, readonly) OWSMessageSender *messageSender; @end +#pragma mark - + @implementation SendExternalFileViewController - (void)loadView @@ -35,25 +39,7 @@ OWSAssert(self.attachment); OWSAssert(thread); - // We should have a valid filename. - OWSAssert(self.attachment.filename.length > 0); - NSString *fileExtension = [self.attachment.filename pathExtension].lowercaseString; - OWSAssert(fileExtension.length > 0); - NSSet *textExtensions = [NSSet setWithArray:@[ - @"txt", - @"url", - ]]; - NSString *text = nil; - if ([textExtensions containsObject:fileExtension]) { - text = [[NSString alloc] initWithData:self.attachment.data encoding:NSUTF8StringEncoding]; - OWSAssert(text); - } - - if (text) { - [ThreadUtil sendMessageWithText:text inThread:thread messageSender:self.messageSender]; - } else { - [ThreadUtil sendMessageWithAttachment:self.attachment inThread:thread messageSender:self.messageSender]; - } + [ThreadUtil sendMessageWithAttachment:self.attachment inThread:thread messageSender:self.messageSender]; [Environment messageThreadId:thread.uniqueId]; } @@ -64,3 +50,5 @@ } @end + +NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/SignalAttachment.swift b/Signal/src/ViewControllers/SignalAttachment.swift index c5462596e..584948a0b 100644 --- a/Signal/src/ViewControllers/SignalAttachment.swift +++ b/Signal/src/ViewControllers/SignalAttachment.swift @@ -283,7 +283,7 @@ class SignalAttachment: NSObject { return UIPasteboard.general.numberOfItems > 0 } - public class func pasteBoardHasText() -> Bool { + public class func pasteboardHasText() -> Bool { if UIPasteboard.general.numberOfItems < 1 { return false } diff --git a/Signal/src/ViewControllers/ThreadViewHelper.h b/Signal/src/ViewControllers/ThreadViewHelper.h index 86367e4ec..5d88fce1a 100644 --- a/Signal/src/ViewControllers/ThreadViewHelper.h +++ b/Signal/src/ViewControllers/ThreadViewHelper.h @@ -12,7 +12,11 @@ @class TSThread; -// A helper class +// A helper class for views that want to present the list of threads +// that show up in home view, and in the same order. +// +// It observes changes to the threads & their ordering and informs +// its delegate when they happen. @interface ThreadViewHelper : NSObject @property (nonatomic, weak) id delegate; diff --git a/Signal/src/ViewControllers/ThreadViewHelper.m b/Signal/src/ViewControllers/ThreadViewHelper.m index 757aabd73..cfb12b421 100644 --- a/Signal/src/ViewControllers/ThreadViewHelper.m +++ b/Signal/src/ViewControllers/ThreadViewHelper.m @@ -118,7 +118,7 @@ } }]; - _threads = threads; + _threads = [threads copy]; } #pragma mark - Logging