Use attachment pointers to restore attachments from backup.

pull/1/head
Matthew Chen 7 years ago
parent 90e7df5515
commit e72dafb08e

@ -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)

@ -8,7 +8,6 @@ NS_ASSUME_NONNULL_BEGIN
@class ConversationViewCell;
@class OWSContactOffersInteraction;
@class OWSContactsManager;
@class TSAttachmentPointer;
@class TSAttachmentStream;
@class TSCall;
@class TSErrorMessage;

@ -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

@ -22,7 +22,7 @@ typedef NS_ENUM(NSUInteger, OWSBackupState) {
@class OWSBackupIO;
@class OWSPrimaryStorage;
@class TSAttachmentStream;
@class TSAttachmentPointer;
@class TSThread;
@interface OWSBackup : NSObject

@ -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 {

@ -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);

@ -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<TSAttachmentPointer *> *attachmentPointers;
- (instancetype)init NS_UNAVAILABLE;
/*
* Retry fetching failed attachment download
*/
- (instancetype)initWithAttachmentPointers:(NSArray<TSAttachmentPointer *> *)attachmentPointers
NS_DESIGNATED_INITIALIZER;
- (void)fetchAttachmentsForMessage:(nullable TSMessage *)message
transaction:(YapDatabaseReadWriteTransaction *)transaction
success:(void (^)(NSArray<TSAttachmentStream *> *attachmentStreams))successHandler
failure:(void (^)(NSError *error))failureHandler;
@end
NS_ASSUME_NONNULL_END
Loading…
Cancel
Save