diff --git a/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift b/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift index af3702dc2..6473a3e50 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift +++ b/Signal/src/ViewControllers/ConversationView/Cells/ConversationMediaView.swift @@ -86,6 +86,12 @@ public class ConversationMediaView: UIView { configure(forError: .invalid) return } + guard attachmentPointer.pointerType == .incoming else { + // TODO: Show "restoring" indicator and possibly progress. + owsFailDebug("Attachment is restorying from backup.") + configure(forError: .missing) + return + } guard let attachmentId = attachmentPointer.uniqueId else { owsFailDebug("Attachment missing unique ID.") configure(forError: .invalid) diff --git a/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h b/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h index cc2c1a022..1b4f94496 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h +++ b/Signal/src/ViewControllers/ConversationView/Cells/ConversationViewCell.h @@ -8,7 +8,6 @@ NS_ASSUME_NONNULL_BEGIN @class ConversationViewCell; @class OWSContactOffersInteraction; @class OWSContactsManager; -@class TSAttachmentPointer; @class TSAttachmentStream; @class TSCall; @class TSErrorMessage; diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m index b323e39b4..4b9adb061 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageBubbleView.m @@ -835,6 +835,8 @@ const UIDataDetectorTypes kOWSAllowedDataDetectorTypes { OWSAssertDebug(self.attachmentPointer); + // TODO: We probably want to do something different for attachments + // being restored from backup. AttachmentPointerView *downloadView = [[AttachmentPointerView alloc] initWithAttachmentPointer:self.attachmentPointer isIncoming:self.isIncoming diff --git a/Signal/src/util/Backup/OWSBackup.h b/Signal/src/util/Backup/OWSBackup.h index 6cb703ac4..6894a33d1 100644 --- a/Signal/src/util/Backup/OWSBackup.h +++ b/Signal/src/util/Backup/OWSBackup.h @@ -22,7 +22,7 @@ typedef NS_ENUM(NSUInteger, OWSBackupState) { @class OWSBackupIO; @class OWSPrimaryStorage; -@class TSAttachmentStream; +@class TSAttachmentPointer; @class TSThread; @interface OWSBackup : NSObject diff --git a/Signal/src/util/Backup/OWSBackupLazyRestoreJob.swift b/Signal/src/util/Backup/OWSBackupLazyRestoreJob.swift index 184572823..2aace7dd1 100644 --- a/Signal/src/util/Backup/OWSBackupLazyRestoreJob.swift +++ b/Signal/src/util/Backup/OWSBackupLazyRestoreJob.swift @@ -68,7 +68,8 @@ public class OWSBackupLazyRestoreJob: NSObject { return } attachmentIdsCopy.removeLast() - guard let attachment = TSAttachmentStream.fetch(uniqueId: attachmentId) else { + guard let attachment = TSAttachment.fetch(uniqueId: attachmentId), + let attachmentPointer = attachment as? TSAttachmentPointer else { Logger.warn("could not load attachment.") // Not necessarily an error. // The attachment might have been deleted since the job began. @@ -76,7 +77,7 @@ public class OWSBackupLazyRestoreJob: NSObject { tryToRestoreNextAttachment(attachmentIds: attachmentIds, backupIO: backupIO) return } - OWSBackup.shared().lazyRestoreAttachment(attachment, + OWSBackup.shared().lazyRestoreAttachment(attachmentPointer, backupIO: backupIO, completion: { (success) in if success { diff --git a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentDownloads.m b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentDownloads.m index a5d3d3a94..fc855804a 100644 --- a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentDownloads.m +++ b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentDownloads.m @@ -147,6 +147,10 @@ typedef void (^AttachmentDownloadFailure)(NSError *error); [attachmentStreams addObject:attachmentStream]; } else if ([attachment isKindOfClass:[TSAttachmentPointer class]]) { TSAttachmentPointer *attachmentPointer = (TSAttachmentPointer *)attachment; + if (attachmentPointer.pointerType != TSAttachmentPointerTypeIncoming) { + OWSLogInfo(@"Ignoring restoring attachment."); + continue; + } [attachmentPointers addObject:attachmentPointer]; } else { OWSFailDebug(@"Unexpected attachment type: %@", attachment.class); diff --git a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h b/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h deleted file mode 100644 index 44fadda8d..000000000 --- a/SignalServiceKit/src/Messages/Attachments/OWSAttachmentsProcessor.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// Copyright (c) 2018 Open Whisper Systems. All rights reserved. -// - -NS_ASSUME_NONNULL_BEGIN - -extern NSString *const kAttachmentDownloadProgressNotification; -extern NSString *const kAttachmentDownloadProgressKey; -extern NSString *const kAttachmentDownloadAttachmentIDKey; - -@class OWSPrimaryStorage; -@class SSKProtoAttachmentPointer; -@class TSAttachmentPointer; -@class TSAttachmentStream; -@class TSMessage; -@class TSNetworkManager; -@class TSThread; -@class YapDatabaseReadWriteTransaction; - -/** - * Given incoming attachment protos, determines which we support. - * It can download those that we support and notifies threads when it receives unsupported attachments. - */ -@interface OWSAttachmentsProcessor : NSObject - -@property (nonatomic, readonly) NSArray *attachmentPointers; - -- (instancetype)init NS_UNAVAILABLE; - -/* - * Retry fetching failed attachment download - */ -- (instancetype)initWithAttachmentPointers:(NSArray *)attachmentPointers - NS_DESIGNATED_INITIALIZER; - -- (void)fetchAttachmentsForMessage:(nullable TSMessage *)message - transaction:(YapDatabaseReadWriteTransaction *)transaction - success:(void (^)(NSArray *attachmentStreams))successHandler - failure:(void (^)(NSError *error))failureHandler; -@end - -NS_ASSUME_NONNULL_END