mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Improve handling of incomplete and failed attachment downloads.
// FREEBIE
This commit is contained in:
parent
fbd3859a85
commit
bdde3c73c5
5 changed files with 31 additions and 7 deletions
|
@ -331,7 +331,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (void)setAttachment:(TSAttachmentPointer *)pointer isDownloadingInMessage:(nullable TSMessage *)message
|
||||
{
|
||||
pointer.downloading = YES;
|
||||
pointer.state = TSAttachmentPointerStateDownloading;
|
||||
[pointer save];
|
||||
if (message) {
|
||||
[message touch];
|
||||
|
@ -340,8 +340,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (void)setAttachment:(TSAttachmentPointer *)pointer didFailInMessage:(nullable TSMessage *)message
|
||||
{
|
||||
pointer.downloading = NO;
|
||||
pointer.failed = YES;
|
||||
pointer.state = TSAttachmentPointerStateFailed;
|
||||
[pointer save];
|
||||
if (message) {
|
||||
[message touch];
|
||||
|
|
|
@ -39,6 +39,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// that represent downloaded incoming attachments.
|
||||
- (instancetype)initWithPointer:(TSAttachment *)pointer;
|
||||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)coder;
|
||||
|
||||
- (void)upgradeFromAttachmentSchemaVersion:(NSUInteger)attachmentSchemaVersion;
|
||||
|
||||
@end
|
||||
|
|
|
@ -6,6 +6,12 @@
|
|||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef NS_ENUM(NSUInteger, TSAttachmentPointerState) {
|
||||
TSAttachmentPointerStateEnqueued = 0,
|
||||
TSAttachmentPointerStateDownloading = 1,
|
||||
TSAttachmentPointerStateFailed = 2,
|
||||
};
|
||||
|
||||
/**
|
||||
* A TSAttachmentPointer is a yet-to-be-downloaded attachment.
|
||||
*/
|
||||
|
@ -18,8 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
relay:(NSString *)relay NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
@property (nonatomic, readonly) NSString *relay;
|
||||
@property (atomic, readwrite, getter=isDownloading) BOOL downloading;
|
||||
@property (atomic, readwrite, getter=hasFailed) BOOL failed;
|
||||
@property (atomic) TSAttachmentPointerState state;
|
||||
|
||||
// Though now required, `digest` may be null for pre-existing records or from
|
||||
// messages received from other clients
|
||||
|
|
|
@ -8,6 +8,23 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@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
|
||||
key:(NSData *)key
|
||||
digest:(nullable NSData *)digest
|
||||
|
@ -20,8 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
|
||||
_digest = digest;
|
||||
_failed = NO;
|
||||
_downloading = NO;
|
||||
_state = TSAttachmentPointerStateEnqueued;
|
||||
_relay = relay;
|
||||
|
||||
return self;
|
||||
|
|
|
@ -21,6 +21,8 @@ static NSString *const OWSFailedMessagesJobMessageStateIndex = @"index_outoing_m
|
|||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSFailedMessagesJob
|
||||
|
||||
- (instancetype)initWithStorageManager:(TSStorageManager *)storageManager
|
||||
|
|
Loading…
Reference in a new issue