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_DownloadingAttachment,
OWSMessageCellType_ContactShare,
OWSMessageCellType_MediaGallery,
};
NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);

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

@ -59,7 +59,11 @@ typedef NS_ENUM(NSUInteger, TSAttachmentType) {
- (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;

@ -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
{
return self.attachmentType == TSAttachmentTypeVoiceMessage;

@ -43,11 +43,6 @@ typedef void (^OWSThumbnailFailure)(void);
- (nullable NSData *)validStillImageData;
#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) NSString *originalFilePath;
@property (nonatomic, readonly, nullable) NSURL *originalMediaURL;
@ -96,8 +91,9 @@ typedef void (^OWSThumbnailFailure)(void);
#pragma mark - Validation
- (BOOL)isValidImage;
- (BOOL)isValidVideo;
@property (nonatomic, readonly) BOOL isValidImage;
@property (nonatomic, readonly) BOOL isValidVideo;
@property (nonatomic, readonly) BOOL isValidMedia;
#pragma mark - Update With... Methods

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

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

Loading…
Cancel
Save