diff --git a/src/Messages/Attachments/OWSAttachmentsProcessor.m b/src/Messages/Attachments/OWSAttachmentsProcessor.m index 2cd0d4dad..766a372b7 100644 --- a/src/Messages/Attachments/OWSAttachmentsProcessor.m +++ b/src/Messages/Attachments/OWSAttachmentsProcessor.m @@ -79,20 +79,9 @@ NS_ASSUME_NONNULL_BEGIN [attachmentIds addObject:pointer.uniqueId]; - // TODO: We need to revisit isSupportedMIMEType. - if ([MIMETypeUtil isSupportedMIMEType:pointer.contentType] || - [pointer.contentType isEqualToString:OWSMimeTypeOversizeTextMessage] || - [pointer.contentType isEqualToString:OWSMimeTypeUnknownForTests]) { - [pointer save]; - [supportedAttachmentPointers addObject:pointer]; - [supportedAttachmentIds addObject:pointer.uniqueId]; - } else { - DDLogError(@"%@ Received unsupported attachment of type: %@", self.tag, pointer.contentType); - TSInfoMessage *infoMessage = [[TSInfoMessage alloc] initWithTimestamp:timestamp - inThread:thread - messageType:TSInfoMessageTypeUnsupportedMessage]; - [infoMessage save]; - } + [pointer save]; + [supportedAttachmentPointers addObject:pointer]; + [supportedAttachmentIds addObject:pointer.uniqueId]; } _attachmentIds = [attachmentIds copy]; diff --git a/src/Util/MIMETypeUtil.h b/src/Util/MIMETypeUtil.h index 2ec495994..36b415d3b 100644 --- a/src/Util/MIMETypeUtil.h +++ b/src/Util/MIMETypeUtil.h @@ -9,7 +9,6 @@ extern NSString *const OWSMimeTypeUnknownForTests; @interface MIMETypeUtil : NSObject -+ (BOOL)isSupportedMIMEType:(NSString *)contentType; + (BOOL)isSupportedVideoMIMEType:(NSString *)contentType; + (BOOL)isSupportedAudioMIMEType:(NSString *)contentType; + (BOOL)isSupportedImageMIMEType:(NSString *)contentType; diff --git a/src/Util/MIMETypeUtil.m b/src/Util/MIMETypeUtil.m index fb8ab8f0a..38b829659 100644 --- a/src/Util/MIMETypeUtil.m +++ b/src/Util/MIMETypeUtil.m @@ -200,11 +200,6 @@ NSString *const OWSMimeTypeUnknownForTests = @"unknown/mimetype"; return [[self supportedBinaryDataMIMETypesToExtensionTypes] objectForKey:contentType] != nil; } -+ (BOOL)isSupportedMIMEType:(NSString *)contentType { - return [self isSupportedImageMIMEType:contentType] || [self isSupportedAudioMIMEType:contentType] || - [self isSupportedVideoMIMEType:contentType] || [self isSupportedAnimatedMIMEType:contentType]; -} - + (BOOL)isSupportedVideoFile:(NSString *)filePath { return [[self supportedVideoExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]] != nil; } @@ -294,9 +289,18 @@ NSString *const OWSMimeTypeUnknownForTests = @"unknown/mimetype"; } else if ([self isBinaryData:contentType]) { return [MIMETypeUtil filePathForBinaryData:uniqueId ofMIMEType:contentType inFolder:folder]; } else if ([contentType isEqualToString:OWSMimeTypeOversizeTextMessage]) { - return [MIMETypeUtil filePathForOversizeTextMessage:uniqueId inFolder:folder]; + // This file extension is arbitrary - it should never be exposed to the user or + // be used outside the app. + return [self filePathForData:uniqueId withFileExtension:@"signal-text-message" inFolder:folder]; } else if ([contentType isEqualToString:OWSMimeTypeUnknownForTests]) { - return [MIMETypeUtil filePathForUnknownContent:uniqueId inFolder:folder]; + // This file extension is arbitrary - it should never be exposed to the user or + // be used outside the app. + return [self filePathForData:uniqueId withFileExtension:@"unknown" inFolder:folder]; + } + + NSString *fileExtension = [self fileExtensionForMIMEType:contentType]; + if (fileExtension) { + return [self filePathForData:uniqueId withFileExtension:fileExtension inFolder:folder]; } DDLogError(@"Got asked for path of file %@ which is unsupported", contentType); @@ -350,18 +354,11 @@ NSString *const OWSMimeTypeUnknownForTests = @"unknown/mimetype"; stringByAppendingPathExtension:[self getSupportedExtensionFromBinaryDataMIMEType:contentType]]; } -+ (NSString *)filePathForOversizeTextMessage:(NSString *)uniqueId inFolder:(NSString *)folder { - // This file extension is arbitrary - it should never be exposed to the user or - // be used outside the app. - return [[folder stringByAppendingFormat:@"/%@", uniqueId] - stringByAppendingPathExtension:@"signal-text-message"]; -} - -+ (NSString *)filePathForUnknownContent:(NSString *)uniqueId inFolder:(NSString *)folder { - // This file extension is arbitrary - it should never be exposed to the user or - // be used outside the app. - return [[folder stringByAppendingFormat:@"/%@", uniqueId] - stringByAppendingPathExtension:@"unknown"]; ++ (NSString *)filePathForData:(NSString *)uniqueId + withFileExtension:(NSString *)fileExtension + inFolder:(NSString *)folder +{ + return [[folder stringByAppendingFormat:@"/%@", uniqueId] stringByAppendingPathExtension:fileExtension]; } #if TARGET_OS_IPHONE