From 351f9ea263536fdb7ab49215858a9dc12c2bcf26 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 6 Apr 2018 17:59:42 -0400 Subject: [PATCH] Simplify attachment processor We've accepted all attachment types for a long while now. // FREEBIE --- .../Attachments/OWSAttachmentsProcessor.h | 5 ++--- .../Attachments/OWSAttachmentsProcessor.m | 19 +++++++------------ .../src/Messages/OWSMessageManager.m | 11 +++++------ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h index 68d70f7e8..dbab5b8a4 100644 --- a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h +++ b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h @@ -23,9 +23,8 @@ extern NSString *const kAttachmentDownloadAttachmentIDKey; */ @interface OWSAttachmentsProcessor : NSObject -@property (nullable, nonatomic, readonly) NSArray *attachmentIds; -@property (nonatomic, readonly) NSArray *supportedAttachmentIds; -@property (nonatomic, readonly) NSArray *supportedAttachmentPointers; +@property (nonatomic, readonly) NSArray *attachmentIds; +@property (nonatomic, readonly) NSArray *attachmentPointers; @property (nonatomic, readonly) BOOL hasSupportedAttachments; - (instancetype)init NS_UNAVAILABLE; diff --git a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m index 384405d29..b25995670 100644 --- a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m +++ b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.m @@ -53,8 +53,8 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f; _networkManager = networkManager; _primaryStorage = primaryStorage; - _supportedAttachmentPointers = @[ attachmentPointer ]; - _supportedAttachmentIds = @[ attachmentPointer.uniqueId ]; + _attachmentPointers = @[ attachmentPointer ]; + _attachmentIds = @[ attachmentPointer.uniqueId ]; return self; } @@ -74,11 +74,9 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f; _primaryStorage = primaryStorage; NSMutableArray *attachmentIds = [NSMutableArray new]; - NSMutableArray *supportedAttachmentPointers = [NSMutableArray new]; - NSMutableArray *supportedAttachmentIds = [NSMutableArray new]; + NSMutableArray *attachmentPointers = [NSMutableArray new]; for (OWSSignalServiceProtosAttachmentPointer *attachmentProto in attachmentProtos) { - OWSAssert(attachmentProto.id != 0); OWSAssert(attachmentProto.key != nil); OWSAssert(attachmentProto.contentType != nil); @@ -104,15 +102,12 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f; attachmentType:attachmentType]; [attachmentIds addObject:pointer.uniqueId]; - [pointer saveWithTransaction:transaction]; - [supportedAttachmentPointers addObject:pointer]; - [supportedAttachmentIds addObject:pointer.uniqueId]; + [attachmentPointers addObject:pointer]; } _attachmentIds = [attachmentIds copy]; - _supportedAttachmentPointers = [supportedAttachmentPointers copy]; - _supportedAttachmentIds = [supportedAttachmentIds copy]; + _attachmentPointers = [attachmentPointers copy]; return self; } @@ -138,7 +133,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f; { OWSAssert(transaction); - for (TSAttachmentPointer *attachmentPointer in self.supportedAttachmentPointers) { + for (TSAttachmentPointer *attachmentPointer in self.attachmentPointers) { [self retrieveAttachment:attachmentPointer message:message transaction:transaction @@ -434,7 +429,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f; - (BOOL)hasSupportedAttachments { - return self.supportedAttachmentPointers.count > 0; + return self.attachmentPointers.count > 0; } @end diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index b326fbb4f..6cc606b99 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -561,11 +561,10 @@ NS_ASSUME_NONNULL_BEGIN return; } - TSIncomingMessage *_Nullable createdMessage = - [self handleReceivedEnvelope:envelope - withDataMessage:dataMessage - attachmentIds:attachmentsProcessor.supportedAttachmentIds - transaction:transaction]; + TSIncomingMessage *_Nullable createdMessage = [self handleReceivedEnvelope:envelope + withDataMessage:dataMessage + attachmentIds:attachmentsProcessor.attachmentIds + transaction:transaction]; if (!createdMessage) { return; @@ -1111,7 +1110,7 @@ NS_ASSUME_NONNULL_BEGIN // if (!attachmentsProcessor.hasSupportedAttachments) { // attachments = @[]; // } else { - // attachments = attachmentsProcessor.supportedAttachmentPointers; + // attachments = attachmentsProcessor.attachmentPointers; // } // // [attachmentsProcessor fetchAttachmentsForMessage:nil