From f2c0985907ec3d11b3b472fb0207e4302a2c75a6 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 5 Nov 2018 09:53:48 -0500 Subject: [PATCH] Add 'is valid media?' method. --- .../ConversationView/ConversationViewItem.h | 1 + .../ConversationView/ConversationViewItem.m | 2 ++ .../src/Messages/Attachments/TSAttachment.h | 6 ++++- .../src/Messages/Attachments/TSAttachment.m | 20 ++++++++++++++++ .../Messages/Attachments/TSAttachmentStream.h | 10 +++----- .../Messages/Attachments/TSAttachmentStream.m | 23 ++++++++++--------- .../src/Storage/OWSMediaGalleryFinder.m | 14 +---------- 7 files changed, 44 insertions(+), 32 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h index 89633bdc3..f0f8812a2 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.h @@ -18,6 +18,7 @@ typedef NS_ENUM(NSInteger, OWSMessageCellType) { OWSMessageCellType_GenericAttachment, OWSMessageCellType_DownloadingAttachment, OWSMessageCellType_ContactShare, + OWSMessageCellType_MediaGallery, }; NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType); diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m index be855291b..205dba705 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewItem.m @@ -41,6 +41,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType) return @"OWSMessageCellType_Unknown"; case OWSMessageCellType_ContactShare: return @"OWSMessageCellType_ContactShare"; + case OWSMessageCellType_MediaGallery: + return @"OWSMessageCellType_MediaGallery"; } } diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachment.h b/SignalServiceKit/src/Messages/Attachments/TSAttachment.h index 3c155f65f..30489914c 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachment.h +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachment.h @@ -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; diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachment.m b/SignalServiceKit/src/Messages/Attachments/TSAttachment.m index b829245bf..fde6ddc2f 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachment.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachment.m @@ -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; diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h index 553619328..85bead9cd 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.h @@ -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 diff --git a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m index cc19429f9..0f3bbe561 100644 --- a/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m +++ b/SignalServiceKit/src/Messages/Attachments/TSAttachmentStream.m @@ -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 diff --git a/SignalServiceKit/src/Storage/OWSMediaGalleryFinder.m b/SignalServiceKit/src/Storage/OWSMediaGalleryFinder.m index b3a0b3919..1e1497830 100644 --- a/SignalServiceKit/src/Storage/OWSMediaGalleryFinder.m +++ b/SignalServiceKit/src/Storage/OWSMediaGalleryFinder.m @@ -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