Merge pull request #307 from RyanRory/retry-attachment-downloads-for-NSE

Fix Attachment Downloading
This commit is contained in:
Niels Andriesse 2020-11-12 11:09:34 +11:00 committed by GitHub
commit 8003370b89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 0 deletions

View File

@ -1235,6 +1235,18 @@ static const int kYapDatabaseRangeMaxLength = 25000;
OWSAssertDebug(!viewItemCache[interaction.uniqueId]);
viewItemCache[interaction.uniqueId] = viewItem;
[viewItems addObject:viewItem];
TSMessage *message = (TSMessage *)viewItem.interaction;
if (message.hasAttachmentsInNSE) {
[SSKEnvironment.shared.attachmentDownloads downloadAttachmentsForMessage:message
transaction:transaction
success:^(NSArray<TSAttachmentStream *> *attachmentStreams) {
OWSLogInfo(@"Successfully redownloaded attachment in thread: %@", message.thread);
}
failure:^(NSError *error) {
OWSLogWarn(@"Failed to redownload message with error: %@", error);
}];
}
return viewItem;
};

View File

@ -290,6 +290,13 @@ typedef void (^AttachmentDownloadFailure)(NSError *error);
[job.attachmentPointer saveWithTransaction:transaction];
if (job.message) {
if (!CurrentAppContext().isMainApp) {
job.message.hasAttachmentsInNSE = true;
} else {
job.message.hasAttachmentsInNSE = false;
}
[job.message saveWithTransaction:transaction];
[job.message touchWithTransaction:transaction];
}
}];

View File

@ -34,6 +34,8 @@ NS_ASSUME_NONNULL_BEGIN
// Open groups
@property (nonatomic) uint64_t openGroupServerMessageID;
@property (nonatomic, readonly) BOOL isOpenGroupMessage;
// Attachments in NSE
@property (nonatomic) BOOL hasAttachmentsInNSE;
- (instancetype)initInteractionWithTimestamp:(uint64_t)timestamp inThread:(TSThread *)thread NS_UNAVAILABLE;

View File

@ -3,6 +3,8 @@
//
#import "OWSFailedAttachmentDownloadsJob.h"
#import "SSKEnvironment.h"
#import "OWSAttachmentDownloads.h"
#import "OWSPrimaryStorage.h"
#import "TSAttachmentPointer.h"
#import <YapDatabase/YapDatabase.h>
@ -25,6 +27,12 @@ static NSString *const OWSFailedAttachmentDownloadsJobAttachmentStateIndex = @"i
@implementation OWSFailedAttachmentDownloadsJob
- (OWSAttachmentDownloads *)attachmentDownloads
{
return SSKEnvironment.shared.attachmentDownloads;
}
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
{
self = [super init];