Simplify attachment processor

We've accepted all attachment types for a long while now.

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 3252866727
commit 351f9ea263

@ -23,9 +23,8 @@ extern NSString *const kAttachmentDownloadAttachmentIDKey;
*/ */
@interface OWSAttachmentsProcessor : NSObject @interface OWSAttachmentsProcessor : NSObject
@property (nullable, nonatomic, readonly) NSArray<NSString *> *attachmentIds; @property (nonatomic, readonly) NSArray<NSString *> *attachmentIds;
@property (nonatomic, readonly) NSArray<NSString *> *supportedAttachmentIds; @property (nonatomic, readonly) NSArray<TSAttachmentPointer *> *attachmentPointers;
@property (nonatomic, readonly) NSArray<TSAttachmentPointer *> *supportedAttachmentPointers;
@property (nonatomic, readonly) BOOL hasSupportedAttachments; @property (nonatomic, readonly) BOOL hasSupportedAttachments;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;

@ -53,8 +53,8 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
_networkManager = networkManager; _networkManager = networkManager;
_primaryStorage = primaryStorage; _primaryStorage = primaryStorage;
_supportedAttachmentPointers = @[ attachmentPointer ]; _attachmentPointers = @[ attachmentPointer ];
_supportedAttachmentIds = @[ attachmentPointer.uniqueId ]; _attachmentIds = @[ attachmentPointer.uniqueId ];
return self; return self;
} }
@ -74,11 +74,9 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
_primaryStorage = primaryStorage; _primaryStorage = primaryStorage;
NSMutableArray<NSString *> *attachmentIds = [NSMutableArray new]; NSMutableArray<NSString *> *attachmentIds = [NSMutableArray new];
NSMutableArray<TSAttachmentPointer *> *supportedAttachmentPointers = [NSMutableArray new]; NSMutableArray<TSAttachmentPointer *> *attachmentPointers = [NSMutableArray new];
NSMutableArray<NSString *> *supportedAttachmentIds = [NSMutableArray new];
for (OWSSignalServiceProtosAttachmentPointer *attachmentProto in attachmentProtos) { for (OWSSignalServiceProtosAttachmentPointer *attachmentProto in attachmentProtos) {
OWSAssert(attachmentProto.id != 0); OWSAssert(attachmentProto.id != 0);
OWSAssert(attachmentProto.key != nil); OWSAssert(attachmentProto.key != nil);
OWSAssert(attachmentProto.contentType != nil); OWSAssert(attachmentProto.contentType != nil);
@ -104,15 +102,12 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
attachmentType:attachmentType]; attachmentType:attachmentType];
[attachmentIds addObject:pointer.uniqueId]; [attachmentIds addObject:pointer.uniqueId];
[pointer saveWithTransaction:transaction]; [pointer saveWithTransaction:transaction];
[supportedAttachmentPointers addObject:pointer]; [attachmentPointers addObject:pointer];
[supportedAttachmentIds addObject:pointer.uniqueId];
} }
_attachmentIds = [attachmentIds copy]; _attachmentIds = [attachmentIds copy];
_supportedAttachmentPointers = [supportedAttachmentPointers copy]; _attachmentPointers = [attachmentPointers copy];
_supportedAttachmentIds = [supportedAttachmentIds copy];
return self; return self;
} }
@ -138,7 +133,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
{ {
OWSAssert(transaction); OWSAssert(transaction);
for (TSAttachmentPointer *attachmentPointer in self.supportedAttachmentPointers) { for (TSAttachmentPointer *attachmentPointer in self.attachmentPointers) {
[self retrieveAttachment:attachmentPointer [self retrieveAttachment:attachmentPointer
message:message message:message
transaction:transaction transaction:transaction
@ -434,7 +429,7 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
- (BOOL)hasSupportedAttachments - (BOOL)hasSupportedAttachments
{ {
return self.supportedAttachmentPointers.count > 0; return self.attachmentPointers.count > 0;
} }
@end @end

@ -561,11 +561,10 @@ NS_ASSUME_NONNULL_BEGIN
return; return;
} }
TSIncomingMessage *_Nullable createdMessage = TSIncomingMessage *_Nullable createdMessage = [self handleReceivedEnvelope:envelope
[self handleReceivedEnvelope:envelope withDataMessage:dataMessage
withDataMessage:dataMessage attachmentIds:attachmentsProcessor.attachmentIds
attachmentIds:attachmentsProcessor.supportedAttachmentIds transaction:transaction];
transaction:transaction];
if (!createdMessage) { if (!createdMessage) {
return; return;
@ -1111,7 +1110,7 @@ NS_ASSUME_NONNULL_BEGIN
// if (!attachmentsProcessor.hasSupportedAttachments) { // if (!attachmentsProcessor.hasSupportedAttachments) {
// attachments = @[]; // attachments = @[];
// } else { // } else {
// attachments = attachmentsProcessor.supportedAttachmentPointers; // attachments = attachmentsProcessor.attachmentPointers;
// } // }
// //
// [attachmentsProcessor fetchAttachmentsForMessage:nil // [attachmentsProcessor fetchAttachmentsForMessage:nil

Loading…
Cancel
Save