From 6ae3a5395e9b51791ceed508f67884f75e28a942 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Sat, 22 Apr 2017 09:45:20 -0400 Subject: [PATCH] Skip attachment approval dialog for image and video shot by camera. // FREEBIE --- .../ViewControllers/MessagesViewController.m | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Signal/src/ViewControllers/MessagesViewController.m b/Signal/src/ViewControllers/MessagesViewController.m index b37bf6c12..87f29e0bd 100644 --- a/Signal/src/ViewControllers/MessagesViewController.m +++ b/Signal/src/ViewControllers/MessagesViewController.m @@ -2203,6 +2203,7 @@ typedef enum : NSUInteger { } #pragma mark UIDocumentPickerDelegate + - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url { DDLogDebug(@"%@ Picked document at url: %@", self.tag, url); @@ -2382,10 +2383,13 @@ typedef enum : NSUInteger { if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeMovie]) { // Video picked from library or captured with camera + BOOL isFromCamera = picker.sourceType == UIImagePickerControllerSourceTypeCamera; NSURL *videoURL = info[UIImagePickerControllerMediaURL]; [self dismissViewControllerAnimated:YES completion:^{ - [self sendQualityAdjustedAttachmentForVideo:videoURL filename:filename]; + [self sendQualityAdjustedAttachmentForVideo:videoURL + filename:filename + skipApprovalDialog:isFromCamera]; }]; } else if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { // Static Image captured from camera @@ -2410,7 +2414,7 @@ typedef enum : NSUInteger { [self showErrorAlertForAttachment:attachment]; failedToPickAttachment(nil); } else { - [self tryToSendAttachmentIfApproved:attachment]; + [self tryToSendAttachmentIfApproved:attachment skipApprovalDialog:YES]; } } else { failedToPickAttachment(nil); @@ -2491,7 +2495,9 @@ typedef enum : NSUInteger { return [NSURL fileURLWithPath:basePath]; } -- (void)sendQualityAdjustedAttachmentForVideo:(NSURL *)movieURL filename:(NSString *)filename +- (void)sendQualityAdjustedAttachmentForVideo:(NSURL *)movieURL + filename:(NSString *)filename + skipApprovalDialog:(BOOL)skipApprovalDialog { AVAsset *video = [AVAsset assetWithURL:movieURL]; AVAssetExportSession *exportSession = @@ -2517,7 +2523,7 @@ typedef enum : NSUInteger { attachment ? [attachment errorName] : @"Missing data"); [self showErrorAlertForAttachment:attachment]; } else { - [self tryToSendAttachmentIfApproved:attachment]; + [self tryToSendAttachmentIfApproved:attachment skipApprovalDialog:skipApprovalDialog]; } NSError *error; @@ -2987,6 +2993,12 @@ typedef enum : NSUInteger { } - (void)tryToSendAttachmentIfApproved:(SignalAttachment *_Nullable)attachment +{ + [self tryToSendAttachmentIfApproved:attachment skipApprovalDialog:NO]; +} + +- (void)tryToSendAttachmentIfApproved:(SignalAttachment *_Nullable)attachment + skipApprovalDialog:(BOOL)skipApprovalDialog { DDLogError(@"%@ %s", self.tag, __PRETTY_FUNCTION__); @@ -3007,6 +3019,8 @@ typedef enum : NSUInteger { __PRETTY_FUNCTION__, attachment ? [attachment errorName] : @"Missing data"); [self showErrorAlertForAttachment:attachment]; + } else if (skipApprovalDialog) { + [self sendMessageAttachment:attachment]; } else { __weak MessagesViewController *weakSelf = self; UIViewController *viewController =