From 791fee347b21f3c84ae3c801375fcd3c688f94be Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 26 Apr 2017 21:46:13 -0400 Subject: [PATCH 1/6] Improve errors in the 'export with Signal' feature. // FREEBIE --- Signal/src/AppDelegate.m | 47 +++++++++++++++++++ .../ViewControllers/MessagesViewController.m | 2 +- .../translations/en.lproj/Localizable.strings | 18 +++++-- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index cc8ccc7e6..fb3540edb 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -268,30 +268,64 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; NSString *filename = url.lastPathComponent; if ([filename stringByDeletingPathExtension].length < 1) { DDLogError(@"Application opened with URL invalid filename: %@", url); + [self showErrorAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_INVALID_FILENAME", + @"Message for the alert indicating the 'export with signal' file had an " + @"invalid filename.")]; return NO; } NSString *fileExtension = [filename pathExtension]; if (fileExtension.length < 1) { DDLogError(@"Application opened with URL missing file extension: %@", url); + [self showErrorAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_UNKNOWN_TYPE", + @"Message for the alert indicating the 'export with signal' file had " + @"unknown type.")]; return NO; } NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:fileExtension]; if (utiType.length < 1) { DDLogError(@"Application opened with URL of unknown UTI type: %@", url); + [self showErrorAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_UNKNOWN_TYPE", + @"Message for the alert indicating the 'export with signal' file had " + @"unknown type.")]; return NO; } NSData *data = [NSData dataWithContentsOfURL:url]; if (!data) { DDLogError(@"Application opened with URL with unloadable content: %@", url); + [self showErrorAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_DATA", + @"Message for the alert indicating the 'export with signal' data " + @"couldn't be loaded.")]; return NO; } SignalAttachment *attachment = [SignalAttachment attachmentWithData:data dataUTI:utiType filename:filename]; if (!attachment) { DDLogError(@"Application opened with URL with invalid content: %@", url); + [self showErrorAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_ATTACHMENT", + @"Message for the alert indicating the 'export with signal' attachment " + @"couldn't be loaded.")]; return NO; } if ([attachment hasError]) { DDLogError(@"Application opened with URL with content error: %@ %@", url, [attachment errorName]); + [self showErrorAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:[attachment errorName]]; return NO; } DDLogInfo(@"Application opened with URL: %@", url); @@ -318,6 +352,19 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; return NO; } +- (void)showErrorAlertWithTitle:(NSString *)title message:(NSString *)message +{ + OWSAssert(title.length > 0); + OWSAssert(message.length > 0); + + UIAlertController *controller = + [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; + + [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) + style:UIAlertActionStyleDefault + handler:nil]]; +} + - (void)applicationDidBecomeActive:(UIApplication *)application { DDLogWarn(@"%@ applicationDidBecomeActive.", self.tag); diff --git a/Signal/src/ViewControllers/MessagesViewController.m b/Signal/src/ViewControllers/MessagesViewController.m index dbcd6d42f..e0245170c 100644 --- a/Signal/src/ViewControllers/MessagesViewController.m +++ b/Signal/src/ViewControllers/MessagesViewController.m @@ -1025,7 +1025,7 @@ typedef enum : NSUInteger { { [self.collectionView.collectionViewLayout setMessageBubbleFont:[UIFont ows_dynamicTypeBodyFont]]; - self.collectionView.showsVerticalScrollIndicator = NO; + self.collectionView.showsVerticalScrollIndicator = YES; self.collectionView.showsHorizontalScrollIndicator = NO; [self updateLoadEarlierVisible]; diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index a4358a607..d302c6530 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -94,9 +94,6 @@ /* Attachment error message for attachments without any data */ "ATTACHMENT_ERROR_MISSING_DATA" = "Attachment is empty."; -/* Attachment error message for attachments with an invalid file format */ -"ATTACHMENT_ERROR_UNKNOWN_TYPE" = "Attachment is of invalid type"; - /* Accessibility hint describing what you can do with the attachment button */ "ATTACHMENT_HINT" = "Choose or take a picture and then send it"; @@ -433,6 +430,21 @@ /* during registration, embeds {{device type}}, e.g. \"iPhone\" or \"iPad\" */ "EXISTING_USER_REGISTRATION_ALERT_TITLE" = "Activating this %@ will disable Signal on any other device currently associated with this phone number."; +/* Message for the alert indicating the 'export with signal' file had an invalid filename. */ +"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_INVALID_FILENAME" = "Invalid filename."; + +/* Message for the alert indicating the 'export with signal' attachment couldn't be loaded. */ +"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_ATTACHMENT" = "Couldn't load file."; + +/* Message for the alert indicating the 'export with signal' data couldn't be loaded. */ +"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_DATA" = "Couldn't load file."; + +/* Message for the alert indicating the 'export with signal' file had unknown type. */ +"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_UNKNOWN_TYPE" = "Unknown file type."; + +/* Title for the alert indicating the 'export with signal' attachment had an error. */ +"EXPORT_WITH_SIGNAL_ERROR_TITLE" = "Error"; + /* action sheet header when re-sending message which failed because of too many attempts */ "FAILED_SENDING_BECAUSE_RATE_LIMIT" = "Too many failures with this contact. Please try again shortly."; From 782140d36797e60f4989b0d89f36ef3653f6e783 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 27 Apr 2017 09:35:58 -0400 Subject: [PATCH 2/6] Respond to CR. // FREEBIE --- Signal/src/ViewControllers/MessagesViewController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Signal/src/ViewControllers/MessagesViewController.m b/Signal/src/ViewControllers/MessagesViewController.m index e0245170c..dbcd6d42f 100644 --- a/Signal/src/ViewControllers/MessagesViewController.m +++ b/Signal/src/ViewControllers/MessagesViewController.m @@ -1025,7 +1025,7 @@ typedef enum : NSUInteger { { [self.collectionView.collectionViewLayout setMessageBubbleFont:[UIFont ows_dynamicTypeBodyFont]]; - self.collectionView.showsVerticalScrollIndicator = YES; + self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.showsHorizontalScrollIndicator = NO; [self updateLoadEarlierVisible]; From c08e6e0fc6a3cb19bb82923646b69d56e1015ea2 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 27 Apr 2017 09:39:45 -0400 Subject: [PATCH 3/6] =?UTF-8?q?Ignore=20=E2=80=9Copen=20with=20Signal?= =?UTF-8?q?=E2=80=9D=20if=20there=20is=20an=20ongoing=20call.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Signal/src/AppDelegate.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index fb3540edb..026d3d9da 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -265,6 +265,12 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; DDLogWarn(@"Application opened with an unknown URL action: %@", url.host); } } else if ([url.scheme.lowercaseString isEqualToString:@"file"]) { + + if ([Environment getCurrent].callService.call != nil) { + DDLogWarn(@"%@ ignoring 'open with Signal' due to ongoing WebRTC call.", self.tag); + return NO; + } + NSString *filename = url.lastPathComponent; if ([filename stringByDeletingPathExtension].length < 1) { DDLogError(@"Application opened with URL invalid filename: %@", url); From 2cc3232c0197e9ed69626f628ee397e58d402f2b Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 27 Apr 2017 09:42:30 -0400 Subject: [PATCH 4/6] =?UTF-8?q?Fix=20presentation=20of=20=E2=80=9Copen=20w?= =?UTF-8?q?ith=20Signal=E2=80=9D=20errors.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Signal/src/AppDelegate.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 026d3d9da..380db42bd 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -369,6 +369,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:nil]]; + [[Environment getCurrent].signalsViewController.presentedViewController presentViewController:controller + animated:YES + completion:nil]; } - (void)applicationDidBecomeActive:(UIApplication *)application { From 1b61c3b0ce8dc6f083f4ad749be53b8c8509fea4 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 27 Apr 2017 10:00:41 -0400 Subject: [PATCH 5/6] fix attachment-import error alert presentation // FREEBIE --- Signal/src/AppDelegate.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 380db42bd..984651572 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -369,9 +369,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) style:UIAlertActionStyleDefault handler:nil]]; - [[Environment getCurrent].signalsViewController.presentedViewController presentViewController:controller - animated:YES - completion:nil]; + + [[Environment getCurrent].signalsViewController presentTopLevelModalViewController:controller + animateDismissal:YES + animatePresentation:YES]; } - (void)applicationDidBecomeActive:(UIApplication *)application { From 48971478dd2d8af38e8adb44a36c2209e7da0a28 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 27 Apr 2017 09:46:51 -0400 Subject: [PATCH 6/6] Allow importing of any file that's not a directory // FREEBIE --- Signal/src/AppDelegate.m | 41 +++++++++++++++---- .../ViewControllers/MessagesViewController.m | 11 +++-- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 984651572..691a455b7 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -293,17 +293,42 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; @"unknown type.")]; return NO; } - NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:fileExtension]; - if (utiType.length < 1) { + + + NSString *utiType; + NSError *typeError; + [url getResourceValue:&utiType forKey:NSURLTypeIdentifierKey error:&typeError]; + if (typeError) { + DDLogError( + @"%@ Determining type of picked document at url: %@ failed with error: %@", self.tag, url, typeError); + OWSAssert(NO); + } + if (!utiType) { + DDLogDebug(@"%@ falling back to default filetype for picked document at url: %@", self.tag, url); + OWSAssert(NO); + utiType = (__bridge NSString *)kUTTypeData; + } + + NSNumber *isDirectory; + NSError *isDirectoryError; + [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&isDirectoryError]; + if (isDirectoryError) { + DDLogError(@"%@ Determining if picked document at url: %@ was a directory failed with error: %@", + self.tag, + url, + isDirectoryError); + OWSAssert(NO); + return NO; + } else if ([isDirectory boolValue]) { + DDLogInfo(@"%@ User picked directory at url: %@", self.tag, url); DDLogError(@"Application opened with URL of unknown UTI type: %@", url); - [self showErrorAlertWithTitle: - NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", - @"Title for the alert indicating the 'export with signal' attachment had an error.") - message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_UNKNOWN_TYPE", - @"Message for the alert indicating the 'export with signal' file had " - @"unknown type.")]; + [self showErrorAlertWithTitle:NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_TITLE", + @"Alert title when picking a document fails because user picked a directory/bundle") + message:NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_BODY", + @"Alert body when picking a document fails because user picked a directory/bundle")]; return NO; } + NSData *data = [NSData dataWithContentsOfURL:url]; if (!data) { DDLogError(@"Application opened with URL with unloadable content: %@", url); diff --git a/Signal/src/ViewControllers/MessagesViewController.m b/Signal/src/ViewControllers/MessagesViewController.m index dbcd6d42f..b37bf6c12 100644 --- a/Signal/src/ViewControllers/MessagesViewController.m +++ b/Signal/src/ViewControllers/MessagesViewController.m @@ -2216,6 +2216,11 @@ typedef enum : NSUInteger { @"%@ Determining type of picked document at url: %@ failed with error: %@", self.tag, url, typeError); OWSAssert(NO); } + if (!type) { + DDLogDebug(@"%@ falling back to default filetype for picked document at url: %@", self.tag, url); + OWSAssert(NO); + type = (__bridge NSString *)kUTTypeData; + } NSNumber *isDirectory; NSError *isDirectoryError; @@ -2248,12 +2253,6 @@ typedef enum : NSUInteger { return; } - if (!type) { - DDLogDebug(@"%@ falling back to default filetype for picked document at url: %@", self.tag, url); - OWSAssert(NO); - type = (__bridge NSString *)kUTTypeData; - } - NSString *filename = url.lastPathComponent; if (!filename) { DDLogDebug(@"%@ Unable to determine filename from url: %@", self.tag, url);