Add 'is valid media?' method.

pull/1/head
Matthew Chen 7 years ago
parent a5c4d1b9ed
commit f2c0985907

@ -18,6 +18,7 @@ typedef NS_ENUM(NSInteger, OWSMessageCellType) {
OWSMessageCellType_GenericAttachment, OWSMessageCellType_GenericAttachment,
OWSMessageCellType_DownloadingAttachment, OWSMessageCellType_DownloadingAttachment,
OWSMessageCellType_ContactShare, OWSMessageCellType_ContactShare,
OWSMessageCellType_MediaGallery,
}; };
NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType); NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);

@ -41,6 +41,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
return @"OWSMessageCellType_Unknown"; return @"OWSMessageCellType_Unknown";
case OWSMessageCellType_ContactShare: case OWSMessageCellType_ContactShare:
return @"OWSMessageCellType_ContactShare"; return @"OWSMessageCellType_ContactShare";
case OWSMessageCellType_MediaGallery:
return @"OWSMessageCellType_MediaGallery";
} }
} }

@ -59,7 +59,11 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) {
- (void)upgradeFromAttachmentSchemaVersion:(NSUInteger)attachmentSchemaVersion; - (void)upgradeFromAttachmentSchemaVersion:(NSUInteger)attachmentSchemaVersion;
- (BOOL)isVoiceMessage; @property (nonatomic, readonly) BOOL isAnimated;
@property (nonatomic, readonly) BOOL isImage;
@property (nonatomic, readonly) BOOL isVideo;
@property (nonatomic, readonly) BOOL isAudio;
@property (nonatomic, readonly) BOOL isVoiceMessage;
+ (NSString *)emojiForMimeType:(NSString *)contentType; + (NSString *)emojiForMimeType:(NSString *)contentType;

@ -195,6 +195,26 @@ NSUInteger const TSAttachmentSchemaVersion = 4;
} }
} }
- (BOOL)isImage
{
return [MIMETypeUtil isImage:self.contentType];
}
- (BOOL)isVideo
{
return [MIMETypeUtil isVideo:self.contentType];
}
- (BOOL)isAudio
{
return [MIMETypeUtil isAudio:self.contentType];
}
- (BOOL)isAnimated
{
return [MIMETypeUtil isAnimated:self.contentType];
}
- (BOOL)isVoiceMessage - (BOOL)isVoiceMessage
{ {
return self.attachmentType == TSAttachmentTypeVoiceMessage; return self.attachmentType == TSAttachmentTypeVoiceMessage;

@ -43,11 +43,6 @@ typedef void (^OWSThumbnailFailure)(void);
- (nullable NSData *)validStillImageData; - (nullable NSData *)validStillImageData;
#endif #endif
@property (nonatomic, readonly) BOOL isAnimated;
@property (nonatomic, readonly) BOOL isImage;
@property (nonatomic, readonly) BOOL isVideo;
@property (nonatomic, readonly) BOOL isAudio;
@property (nonatomic, readonly, nullable) UIImage *originalImage; @property (nonatomic, readonly, nullable) UIImage *originalImage;
@property (nonatomic, readonly, nullable) NSString *originalFilePath; @property (nonatomic, readonly, nullable) NSString *originalFilePath;
@property (nonatomic, readonly, nullable) NSURL *originalMediaURL; @property (nonatomic, readonly, nullable) NSURL *originalMediaURL;
@ -96,8 +91,9 @@ typedef void (^OWSThumbnailFailure)(void);
#pragma mark - Validation #pragma mark - Validation
- (BOOL)isValidImage; @property (nonatomic, readonly) BOOL isValidImage;
- (BOOL)isValidVideo; @property (nonatomic, readonly) BOOL isValidVideo;
@property (nonatomic, readonly) BOOL isValidMedia;
#pragma mark - Update With... Methods #pragma mark - Update With... Methods

@ -329,20 +329,21 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
[self removeFileWithTransaction:transaction]; [self removeFileWithTransaction:transaction];
} }
- (BOOL)isAnimated { - (BOOL)isValidMedia
return [MIMETypeUtil isAnimated:self.contentType]; {
} if (self.isImage && self.isValidImage) {
return YES;
}
- (BOOL)isImage { if (self.isVideo && self.isValidVideo) {
return [MIMETypeUtil isImage:self.contentType]; return YES;
} }
- (BOOL)isVideo { if (self.isAnimated && self.isValidImage) {
return [MIMETypeUtil isVideo:self.contentType]; return YES;
} }
- (BOOL)isAudio { return NO;
return [MIMETypeUtil isAudio:self.contentType];
} }
#pragma mark - Image Validation #pragma mark - Image Validation

@ -180,19 +180,7 @@ static NSString *const OWSMediaGalleryFinderExtensionName = @"OWSMediaGalleryFin
return NO; return NO;
} }
if (attachment.isImage && attachment.isValidImage) { return attachment.isValidMedia;
return YES;
}
if (attachment.isVideo && attachment.isValidVideo) {
return YES;
}
if (attachment.isAnimated && attachment.isValidImage) {
return YES;
}
return NO;
} }
@end @end

Loading…
Cancel
Save