support sending all files

use generic mimetype when file has unknown extension

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 93fe122323
commit 822f5c8415

@ -12,7 +12,6 @@ enum SignalAttachmentError: Error {
case couldNotParseImage case couldNotParseImage
case couldNotConvertToJpeg case couldNotConvertToJpeg
case invalidFileFormat case invalidFileFormat
case unknownType
} }
extension SignalAttachmentError: LocalizedError { extension SignalAttachmentError: LocalizedError {
@ -30,8 +29,6 @@ extension SignalAttachmentError: LocalizedError {
return NSLocalizedString("ATTACHMENT_ERROR_COULD_NOT_CONVERT_TO_JPEG", comment: "Attachment error message for image attachments which could not be converted to JPEG") 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: case .invalidFileFormat:
return NSLocalizedString("ATTACHMENT_ERROR_INVALID_FILE_FORMAT", comment: "Attachment error message for attachments with an invalid file format") return NSLocalizedString("ATTACHMENT_ERROR_INVALID_FILE_FORMAT", comment: "Attachment error message for attachments with an invalid file format")
case .unknownType:
return NSLocalizedString("ATTACHMENT_ERROR_UNKNOWN_TYPE", comment: "Attachment error message for attachments with an invalid file format")
} }
} }
} }
@ -114,10 +111,6 @@ class SignalAttachment: NSObject {
self.dataUTI = dataUTI self.dataUTI = dataUTI
self.filename = filename self.filename = filename
super.init() super.init()
if self.mimeType == nil {
error = .unknownType
}
} }
// MARK: Methods // MARK: Methods
@ -174,7 +167,7 @@ class SignalAttachment: NSObject {
// 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 {
if dataUTI == SignalAttachment.kOversizeTextAttachmentUTI { if dataUTI == SignalAttachment.kOversizeTextAttachmentUTI {
return OWSMimeTypeOversizeTextMessage return OWSMimeTypeOversizeTextMessage
} }
@ -182,7 +175,7 @@ class SignalAttachment: NSObject {
return OWSMimeTypeUnknownForTests return OWSMimeTypeUnknownForTests
} }
guard let mimeType = UTTypeCopyPreferredTagWithClass(dataUTI as CFString, kUTTagClassMIMEType) else { guard let mimeType = UTTypeCopyPreferredTagWithClass(dataUTI as CFString, kUTTagClassMIMEType) else {
return nil return OWSMimeTypeApplicationOctetStream
} }
return mimeType.takeRetainedValue() as String return mimeType.takeRetainedValue() as String
} }

Loading…
Cancel
Save