Merge branch 'charlesmchen/exportWithSignalErrors'

pull/1/head
Matthew Chen 8 years ago
commit c4e90089d5

@ -268,30 +268,64 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
NSString *filename = url.lastPathComponent; NSString *filename = url.lastPathComponent;
if ([filename stringByDeletingPathExtension].length < 1) { if ([filename stringByDeletingPathExtension].length < 1) {
DDLogError(@"Application opened with URL invalid filename: %@", url); 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; return NO;
} }
NSString *fileExtension = [filename pathExtension]; NSString *fileExtension = [filename pathExtension];
if (fileExtension.length < 1) { if (fileExtension.length < 1) {
DDLogError(@"Application opened with URL missing file extension: %@", url); 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; return NO;
} }
NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:fileExtension]; NSString *utiType = [MIMETypeUtil utiTypeForFileExtension:fileExtension];
if (utiType.length < 1) { if (utiType.length < 1) {
DDLogError(@"Application opened with URL of unknown UTI type: %@", 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.")];
return NO; return NO;
} }
NSData *data = [NSData dataWithContentsOfURL:url]; NSData *data = [NSData dataWithContentsOfURL:url];
if (!data) { if (!data) {
DDLogError(@"Application opened with URL with unloadable content: %@", url); 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; return NO;
} }
SignalAttachment *attachment = [SignalAttachment attachmentWithData:data dataUTI:utiType filename:filename]; SignalAttachment *attachment = [SignalAttachment attachmentWithData:data dataUTI:utiType filename:filename];
if (!attachment) { if (!attachment) {
DDLogError(@"Application opened with URL with invalid content: %@", url); 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; return NO;
} }
if ([attachment hasError]) { if ([attachment hasError]) {
DDLogError(@"Application opened with URL with content error: %@ %@", url, [attachment errorName]); 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; return NO;
} }
DDLogInfo(@"Application opened with URL: %@", url); DDLogInfo(@"Application opened with URL: %@", url);
@ -318,6 +352,19 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
return NO; 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 { - (void)applicationDidBecomeActive:(UIApplication *)application {
DDLogWarn(@"%@ applicationDidBecomeActive.", self.tag); DDLogWarn(@"%@ applicationDidBecomeActive.", self.tag);

@ -94,9 +94,6 @@
/* Attachment error message for attachments without any data */ /* Attachment error message for attachments without any data */
"ATTACHMENT_ERROR_MISSING_DATA" = "Attachment is empty."; "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 */ /* Accessibility hint describing what you can do with the attachment button */
"ATTACHMENT_HINT" = "Choose or take a picture and then send it"; "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\" */ /* 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."; "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 */ /* 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."; "FAILED_SENDING_BECAUSE_RATE_LIMIT" = "Too many failures with this contact. Please try again shortly.";

Loading…
Cancel
Save