Improve handling of incomplete and failed attachment downloads.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent fbd3859a85
commit bdde3c73c5

@ -331,7 +331,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setAttachment:(TSAttachmentPointer *)pointer isDownloadingInMessage:(nullable TSMessage *)message - (void)setAttachment:(TSAttachmentPointer *)pointer isDownloadingInMessage:(nullable TSMessage *)message
{ {
pointer.downloading = YES; pointer.state = TSAttachmentPointerStateDownloading;
[pointer save]; [pointer save];
if (message) { if (message) {
[message touch]; [message touch];
@ -340,8 +340,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setAttachment:(TSAttachmentPointer *)pointer didFailInMessage:(nullable TSMessage *)message - (void)setAttachment:(TSAttachmentPointer *)pointer didFailInMessage:(nullable TSMessage *)message
{ {
pointer.downloading = NO; pointer.state = TSAttachmentPointerStateFailed;
pointer.failed = YES;
[pointer save]; [pointer save];
if (message) { if (message) {
[message touch]; [message touch];

@ -39,6 +39,8 @@ NS_ASSUME_NONNULL_BEGIN
// that represent downloaded incoming attachments. // that represent downloaded incoming attachments.
- (instancetype)initWithPointer:(TSAttachment *)pointer; - (instancetype)initWithPointer:(TSAttachment *)pointer;
- (nullable instancetype)initWithCoder:(NSCoder *)coder;
- (void)upgradeFromAttachmentSchemaVersion:(NSUInteger)attachmentSchemaVersion; - (void)upgradeFromAttachmentSchemaVersion:(NSUInteger)attachmentSchemaVersion;
@end @end

@ -6,6 +6,12 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, TSAttachmentPointerState) {
TSAttachmentPointerStateEnqueued = 0,
TSAttachmentPointerStateDownloading = 1,
TSAttachmentPointerStateFailed = 2,
};
/** /**
* A TSAttachmentPointer is a yet-to-be-downloaded attachment. * A TSAttachmentPointer is a yet-to-be-downloaded attachment.
*/ */
@ -18,8 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
relay:(NSString *)relay NS_DESIGNATED_INITIALIZER; relay:(NSString *)relay NS_DESIGNATED_INITIALIZER;
@property (nonatomic, readonly) NSString *relay; @property (nonatomic, readonly) NSString *relay;
@property (atomic, readwrite, getter=isDownloading) BOOL downloading; @property (atomic) TSAttachmentPointerState state;
@property (atomic, readwrite, getter=hasFailed) BOOL failed;
// Though now required, `digest` may be null for pre-existing records or from // Though now required, `digest` may be null for pre-existing records or from
// messages received from other clients // messages received from other clients

@ -8,6 +8,23 @@ NS_ASSUME_NONNULL_BEGIN
@implementation TSAttachmentPointer @implementation TSAttachmentPointer
- (nullable instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (!self) {
return self;
}
// A TSAttachmentPointer is a yet-to-be-downloaded attachment.
// If this is an old TSAttachmentPointer from another session,
// we know that it failed to complete before the session completed.
if (![coder containsValueForKey:@"state"]) {
_state = TSAttachmentPointerStateFailed;
}
return self;
}
- (instancetype)initWithServerId:(UInt64)serverId - (instancetype)initWithServerId:(UInt64)serverId
key:(NSData *)key key:(NSData *)key
digest:(nullable NSData *)digest digest:(nullable NSData *)digest
@ -20,8 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
} }
_digest = digest; _digest = digest;
_failed = NO; _state = TSAttachmentPointerStateEnqueued;
_downloading = NO;
_relay = relay; _relay = relay;
return self; return self;

@ -21,6 +21,8 @@ static NSString *const OWSFailedMessagesJobMessageStateIndex = @"index_outoing_m
@end @end
#pragma mark -
@implementation OWSFailedMessagesJob @implementation OWSFailedMessagesJob
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager - (instancetype)initWithStorageManager:(TSStorageManager *)storageManager

Loading…
Cancel
Save