mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Merge branch 'charlesmchen/attachmentErrors'
This commit is contained in:
commit
7a7cc34cdd
|
@ -1950,7 +1950,8 @@ typedef enum : NSUInteger {
|
||||||
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
||||||
self.tag,
|
self.tag,
|
||||||
__PRETTY_FUNCTION__,
|
__PRETTY_FUNCTION__,
|
||||||
attachment ? [attachment errorMessage] : @"Missing data");
|
attachment ? [attachment errorName] : @"Missing data");
|
||||||
|
[self showErrorAlertForAttachment:attachment];
|
||||||
failedToPickAttachment(nil);
|
failedToPickAttachment(nil);
|
||||||
} else {
|
} else {
|
||||||
[self sendMessageAttachment:attachment];
|
[self sendMessageAttachment:attachment];
|
||||||
|
@ -1988,21 +1989,21 @@ typedef enum : NSUInteger {
|
||||||
|
|
||||||
SignalAttachment *attachment = [SignalAttachment imageAttachmentWithData:imageData
|
SignalAttachment *attachment = [SignalAttachment imageAttachmentWithData:imageData
|
||||||
dataUTI:dataUTI];
|
dataUTI:dataUTI];
|
||||||
if (!attachment ||
|
[self dismissViewControllerAnimated:YES
|
||||||
[attachment hasError]) {
|
completion:^{
|
||||||
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
OWSAssert([NSThread isMainThread]);
|
||||||
self.tag,
|
if (!attachment ||
|
||||||
__PRETTY_FUNCTION__,
|
[attachment hasError]) {
|
||||||
attachment ? [attachment errorMessage] : @"Missing data");
|
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
||||||
failedToPickAttachment(nil);
|
self.tag,
|
||||||
} else {
|
__PRETTY_FUNCTION__,
|
||||||
[self dismissViewControllerAnimated:YES
|
attachment ? [attachment errorName] : @"Missing data");
|
||||||
completion:^{
|
[self showErrorAlertForAttachment:attachment];
|
||||||
OWSAssert([NSThread isMainThread]);
|
failedToPickAttachment(nil);
|
||||||
|
} else {
|
||||||
[self sendMessageAttachment:attachment];
|
[self sendMessageAttachment:attachment];
|
||||||
}];
|
}
|
||||||
}
|
}];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2082,8 +2083,8 @@ typedef enum : NSUInteger {
|
||||||
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
||||||
self.tag,
|
self.tag,
|
||||||
__PRETTY_FUNCTION__,
|
__PRETTY_FUNCTION__,
|
||||||
attachment ? [attachment errorMessage] : @"Missing data");
|
attachment ? [attachment errorName] : @"Missing data");
|
||||||
// TODO: How should we handle errors here?
|
[self showErrorAlertForAttachment:attachment];
|
||||||
} else {
|
} else {
|
||||||
[self sendMessageAttachment:attachment];
|
[self sendMessageAttachment:attachment];
|
||||||
}
|
}
|
||||||
|
@ -2318,8 +2319,8 @@ typedef enum : NSUInteger {
|
||||||
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
||||||
self.tag,
|
self.tag,
|
||||||
__PRETTY_FUNCTION__,
|
__PRETTY_FUNCTION__,
|
||||||
attachment ? [attachment errorMessage] : @"Missing data");
|
attachment ? [attachment errorName] : @"Missing data");
|
||||||
// TODO: How should we handle errors here?
|
[self showErrorAlertForAttachment:attachment];
|
||||||
} else {
|
} else {
|
||||||
[self sendMessageAttachment:attachment];
|
[self sendMessageAttachment:attachment];
|
||||||
}
|
}
|
||||||
|
@ -2558,14 +2559,14 @@ typedef enum : NSUInteger {
|
||||||
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
DDLogWarn(@"%@ %s Invalid attachment: %@.",
|
||||||
self.tag,
|
self.tag,
|
||||||
__PRETTY_FUNCTION__,
|
__PRETTY_FUNCTION__,
|
||||||
attachment ? [attachment errorMessage] : @"Missing data");
|
attachment ? [attachment errorName] : @"Missing data");
|
||||||
// TODO: Add UI.
|
[self showErrorAlertForAttachment:attachment];
|
||||||
} else {
|
} else {
|
||||||
__weak MessagesViewController *weakSelf = self;
|
__weak MessagesViewController *weakSelf = self;
|
||||||
UIViewController *viewController = [[AttachmentApprovalViewController alloc] initWithAttachment:attachment
|
UIViewController *viewController = [[AttachmentApprovalViewController alloc] initWithAttachment:attachment
|
||||||
successCompletion:^{
|
successCompletion:^{
|
||||||
[weakSelf sendMessageAttachment:attachment];
|
[weakSelf sendMessageAttachment:attachment];
|
||||||
}];
|
}];
|
||||||
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
|
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
|
||||||
[self.navigationController presentViewController:navigationController
|
[self.navigationController presentViewController:navigationController
|
||||||
animated:YES
|
animated:YES
|
||||||
|
@ -2573,6 +2574,30 @@ typedef enum : NSUInteger {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)showErrorAlertForAttachment:(SignalAttachment * _Nullable)attachment {
|
||||||
|
OWSAssert(attachment == nil || [attachment hasError]);
|
||||||
|
|
||||||
|
NSString *errorMessage = (attachment
|
||||||
|
? [attachment localizedErrorDescription]
|
||||||
|
: [SignalAttachment missingDataErrorMessage]);
|
||||||
|
|
||||||
|
DDLogError(@"%@ %s: %@",
|
||||||
|
self.tag,
|
||||||
|
__PRETTY_FUNCTION__, errorMessage);
|
||||||
|
|
||||||
|
UIAlertController *controller =
|
||||||
|
[UIAlertController alertControllerWithTitle:NSLocalizedString(@"ATTACHMENT_ERROR_ALERT_TITLE",
|
||||||
|
@"The title of the 'attachment error' alert.")
|
||||||
|
message:errorMessage
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
|
||||||
|
style:UIAlertActionStyleDefault
|
||||||
|
handler:nil]];
|
||||||
|
[self presentViewController:controller
|
||||||
|
animated:YES
|
||||||
|
completion:nil];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Class methods
|
#pragma mark - Class methods
|
||||||
|
|
||||||
+ (UINib *)nib
|
+ (UINib *)nib
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
import MobileCoreServices
|
import MobileCoreServices
|
||||||
|
|
||||||
enum SignalAttachmentError: String {
|
enum SignalAttachmentError: Error {
|
||||||
case missingData
|
case missingData
|
||||||
case fileSizeTooLarge
|
case fileSizeTooLarge
|
||||||
case invalidData
|
case invalidData
|
||||||
|
@ -14,7 +14,26 @@ enum SignalAttachmentError: String {
|
||||||
case invalidFileFormat
|
case invalidFileFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TSImageQuality: Int {
|
extension SignalAttachmentError: LocalizedError {
|
||||||
|
public var errorDescription: String {
|
||||||
|
switch self {
|
||||||
|
case .missingData:
|
||||||
|
return NSLocalizedString("ATTACHMENT_ERROR_MISSING_DATA", comment: "Attachment error message for attachments without any data")
|
||||||
|
case .fileSizeTooLarge:
|
||||||
|
return NSLocalizedString("ATTACHMENT_ERROR_FILE_SIZE_TOO_LARGE", comment: "Attachment error message for attachments whose data exceed file size limits")
|
||||||
|
case .invalidData:
|
||||||
|
return NSLocalizedString("ATTACHMENT_ERROR_INVALID_DATA", comment: "Attachment error message for attachments with invalid data")
|
||||||
|
case .couldNotParseImage:
|
||||||
|
return NSLocalizedString("ATTACHMENT_ERROR_COULD_NOT_PARSE_IMAGE", comment: "Attachment error message for image attachments which cannot be parsed")
|
||||||
|
case .couldNotConvertToJpeg:
|
||||||
|
return NSLocalizedString("ATTACHMENT_ERROR_COULD_NOT_CONVERT_TO_JPEG", comment: "Attachment error message for image attachments which could not be converted to JPEG")
|
||||||
|
case .invalidFileFormat:
|
||||||
|
return NSLocalizedString("ATTACHMENT_ERROR_INVALID_FILE_FORMAT", comment: "Attachment error message for attachments with an invalid file format")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum TSImageQuality {
|
||||||
case uncropped
|
case uncropped
|
||||||
case high
|
case high
|
||||||
case medium
|
case medium
|
||||||
|
@ -91,15 +110,30 @@ class SignalAttachment: NSObject {
|
||||||
return error != nil
|
return error != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var errorMessage: String? {
|
var errorName: String? {
|
||||||
guard let error = error else {
|
guard let error = error else {
|
||||||
// This method should only be called if there is an error.
|
// This method should only be called if there is an error.
|
||||||
assert(false)
|
assert(false)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return "\(error)"
|
return "\(error)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var localizedErrorDescription: String? {
|
||||||
|
guard let error = self.error else {
|
||||||
|
// This method should only be called if there is an error.
|
||||||
|
assert(false)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return "\(error.errorDescription)"
|
||||||
|
}
|
||||||
|
|
||||||
|
class var missingDataErrorMessage: String {
|
||||||
|
return SignalAttachmentError.missingData.errorDescription
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the MIME type for this attachment or nil if no MIME type
|
// Returns the MIME type for this attachment or nil if no MIME type
|
||||||
// can be identified.
|
// can be identified.
|
||||||
var mimeType: String? {
|
var mimeType: String? {
|
||||||
|
|
|
@ -67,6 +67,27 @@
|
||||||
/* No comment provided by engineer. */
|
/* No comment provided by engineer. */
|
||||||
"ATTACHMENT_DOWNLOADING" = "Attachment is downloading";
|
"ATTACHMENT_DOWNLOADING" = "Attachment is downloading";
|
||||||
|
|
||||||
|
/* The title of the 'attachment error' alert. */
|
||||||
|
"ATTACHMENT_ERROR_ALERT_TITLE" = "Error Sending Attachment";
|
||||||
|
|
||||||
|
/* Attachment error message for image attachments which could not be converted to JPEG */
|
||||||
|
"ATTACHMENT_ERROR_COULD_NOT_CONVERT_TO_JPEG" = "Image attachment could not be resized.";
|
||||||
|
|
||||||
|
/* Attachment error message for image attachments which cannot be parsed */
|
||||||
|
"ATTACHMENT_ERROR_COULD_NOT_PARSE_IMAGE" = "Image attachment could not be parsed.";
|
||||||
|
|
||||||
|
/* Attachment error message for attachments whose data exceed file size limits */
|
||||||
|
"ATTACHMENT_ERROR_FILE_SIZE_TOO_LARGE" = "Attachment is too large.";
|
||||||
|
|
||||||
|
/* Attachment error message for attachments with invalid data */
|
||||||
|
"ATTACHMENT_ERROR_INVALID_DATA" = "Attachment has invalid contents.";
|
||||||
|
|
||||||
|
/* Attachment error message for attachments with an invalid file format */
|
||||||
|
"ATTACHMENT_ERROR_INVALID_FILE_FORMAT" = "Attachment has invalid file format.";
|
||||||
|
|
||||||
|
/* Attachment error message for attachments without any data */
|
||||||
|
"ATTACHMENT_ERROR_MISSING_DATA" = "Attachment is empty.";
|
||||||
|
|
||||||
/* 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";
|
||||||
|
|
||||||
|
@ -79,9 +100,6 @@
|
||||||
/* No comment provided by engineer. */
|
/* No comment provided by engineer. */
|
||||||
"AUDIO_PERMISSION_MESSAGE" = "Signal requires access to your microphone to work properly. You can grant this permission in the Settings app >> Privacy >> Microphone >> Signal";
|
"AUDIO_PERMISSION_MESSAGE" = "Signal requires access to your microphone to work properly. You can grant this permission in the Settings app >> Privacy >> Microphone >> Signal";
|
||||||
|
|
||||||
/* Title for call interstitial view */
|
|
||||||
"CALL_INTERSTITIAL_CALLING_LABEL" = "Calling...";
|
|
||||||
|
|
||||||
/* Accessibilty label for placing call button */
|
/* Accessibilty label for placing call button */
|
||||||
"CALL_LABEL" = "Call";
|
"CALL_LABEL" = "Call";
|
||||||
|
|
||||||
|
@ -412,9 +430,6 @@
|
||||||
/* No comment provided by engineer. */
|
/* No comment provided by engineer. */
|
||||||
"INCOMING_INCOMPLETE_CALL" = "Incomplete incoming call from";
|
"INCOMING_INCOMPLETE_CALL" = "Incomplete incoming call from";
|
||||||
|
|
||||||
/* Generic error text when message contents are undisplayable */
|
|
||||||
"INFO_MESSAGE_UNABLE_TO_DISPLAY_MESSAGE" = "Unable to display message.";
|
|
||||||
|
|
||||||
/* Text for button at the top of the contact picker */
|
/* Text for button at the top of the contact picker */
|
||||||
"INVITE_FRIENDS_CONTACT_TABLE_BUTTON" = "Invite Friends to Signal";
|
"INVITE_FRIENDS_CONTACT_TABLE_BUTTON" = "Invite Friends to Signal";
|
||||||
|
|
||||||
|
@ -934,9 +949,6 @@
|
||||||
/* No comment provided by engineer. */
|
/* No comment provided by engineer. */
|
||||||
"TXT_DELETE_TITLE" = "Delete";
|
"TXT_DELETE_TITLE" = "Delete";
|
||||||
|
|
||||||
/* Alert Title */
|
|
||||||
"UNABLE_TO_PLACE_CALL" = "Unable to place call.";
|
|
||||||
|
|
||||||
/* Pressing this button moves an archived thread from the archive back to the inbox */
|
/* Pressing this button moves an archived thread from the archive back to the inbox */
|
||||||
"UNARCHIVE_ACTION" = "Unarchive";
|
"UNARCHIVE_ACTION" = "Unarchive";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue