Respond to CR.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-04-26 12:25:41 -04:00
parent 6e36ce97a5
commit e75ed5e477
9 changed files with 29 additions and 43 deletions

View File

@ -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];

View File

@ -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];

View File

@ -4,6 +4,8 @@
@class TSThread;
NS_ASSUME_NONNULL_BEGIN
@protocol SelectThreadViewControllerDelegate <NSObject>
- (void)threadWasSelected:(TSThread *)thread;
@ -19,3 +21,5 @@
@property (nonatomic, weak) id<SelectThreadViewControllerDelegate> delegate;
@end
NS_ASSUME_NONNULL_END

View File

@ -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;
}

View File

@ -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

View File

@ -9,12 +9,16 @@
#import <SignalServiceKit/OWSMessageSender.h>
#import <SignalServiceKit/TSThread.h>
NS_ASSUME_NONNULL_BEGIN
@interface SendExternalFileViewController () <SelectThreadViewControllerDelegate>
@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<NSString *> *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

View File

@ -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
}

View File

@ -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<ThreadViewHelperDelegate> delegate;

View File

@ -118,7 +118,7 @@
}
}];
_threads = threads;
_threads = [threads copy];
}
#pragma mark - Logging