Improve support for arbitrary attachments.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent da3c4bbac7
commit 12635c65c2

@ -79,20 +79,9 @@ NS_ASSUME_NONNULL_BEGIN
[attachmentIds addObject:pointer.uniqueId]; [attachmentIds addObject:pointer.uniqueId];
// TODO: We need to revisit isSupportedMIMEType. [pointer save];
if ([MIMETypeUtil isSupportedMIMEType:pointer.contentType] || [supportedAttachmentPointers addObject:pointer];
[pointer.contentType isEqualToString:OWSMimeTypeOversizeTextMessage] || [supportedAttachmentIds addObject:pointer.uniqueId];
[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];
}
} }
_attachmentIds = [attachmentIds copy]; _attachmentIds = [attachmentIds copy];

@ -9,7 +9,6 @@ extern NSString *const OWSMimeTypeUnknownForTests;
@interface MIMETypeUtil : NSObject @interface MIMETypeUtil : NSObject
+ (BOOL)isSupportedMIMEType:(NSString *)contentType;
+ (BOOL)isSupportedVideoMIMEType:(NSString *)contentType; + (BOOL)isSupportedVideoMIMEType:(NSString *)contentType;
+ (BOOL)isSupportedAudioMIMEType:(NSString *)contentType; + (BOOL)isSupportedAudioMIMEType:(NSString *)contentType;
+ (BOOL)isSupportedImageMIMEType:(NSString *)contentType; + (BOOL)isSupportedImageMIMEType:(NSString *)contentType;

@ -200,11 +200,6 @@ NSString *const OWSMimeTypeUnknownForTests = @"unknown/mimetype";
return [[self supportedBinaryDataMIMETypesToExtensionTypes] objectForKey:contentType] != nil; 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 { + (BOOL)isSupportedVideoFile:(NSString *)filePath {
return [[self supportedVideoExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]] != nil; return [[self supportedVideoExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]] != nil;
} }
@ -294,9 +289,18 @@ NSString *const OWSMimeTypeUnknownForTests = @"unknown/mimetype";
} else if ([self isBinaryData:contentType]) { } else if ([self isBinaryData:contentType]) {
return [MIMETypeUtil filePathForBinaryData:uniqueId ofMIMEType:contentType inFolder:folder]; return [MIMETypeUtil filePathForBinaryData:uniqueId ofMIMEType:contentType inFolder:folder];
} else if ([contentType isEqualToString:OWSMimeTypeOversizeTextMessage]) { } 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]) { } 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); DDLogError(@"Got asked for path of file %@ which is unsupported", contentType);
@ -350,18 +354,11 @@ NSString *const OWSMimeTypeUnknownForTests = @"unknown/mimetype";
stringByAppendingPathExtension:[self getSupportedExtensionFromBinaryDataMIMEType:contentType]]; stringByAppendingPathExtension:[self getSupportedExtensionFromBinaryDataMIMEType:contentType]];
} }
+ (NSString *)filePathForOversizeTextMessage:(NSString *)uniqueId inFolder:(NSString *)folder { + (NSString *)filePathForData:(NSString *)uniqueId
// This file extension is arbitrary - it should never be exposed to the user or withFileExtension:(NSString *)fileExtension
// be used outside the app. inFolder:(NSString *)folder
return [[folder stringByAppendingFormat:@"/%@", uniqueId] {
stringByAppendingPathExtension:@"signal-text-message"]; return [[folder stringByAppendingFormat:@"/%@", uniqueId] stringByAppendingPathExtension:fileExtension];
}
+ (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"];
} }
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE

Loading…
Cancel
Save