Merge branch 'mkirk/download-progress'

This commit is contained in:
Michael Kirk 2017-04-19 18:36:27 -04:00
commit 1fe0930740
2 changed files with 32 additions and 2 deletions

View File

@ -1,7 +1,13 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
extern NSString *const kAttachmentDownloadProgressNotification;
extern NSString *const kAttachmentDownloadProgressKey;
extern NSString *const kAttachmentDownloadAttachmentIDKey;
@class TSMessage;
@class TSThread;
@class TSNetworkManager;

View File

@ -20,6 +20,14 @@
NS_ASSUME_NONNULL_BEGIN
NSString *const kAttachmentDownloadProgressNotification = @"kAttachmentDownloadProgressNotification";
NSString *const kAttachmentDownloadProgressKey = @"kAttachmentDownloadProgressKey";
NSString *const kAttachmentDownloadAttachmentIDKey = @"kAttachmentDownloadAttachmentIDKey";
// Use a slightly non-zero value to ensure that the progress
// indicator shows up as quickly as possible.
static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
@interface OWSAttachmentsProcessor ()
@property (nonatomic, readonly) TSNetworkManager *networkManager;
@ -259,7 +267,10 @@ NS_ASSUME_NONNULL_BEGIN
abortDownload();
return;
}
[self fireProgressNotification:MAX(kAttachmentDownloadProgressTheta, progress.fractionCompleted)
attachmentId:pointer.uniqueId];
// We only need to check the content length header once.
if (hasCheckedContentLength) {
return;
@ -322,6 +333,19 @@ NS_ASSUME_NONNULL_BEGIN
}];
}
- (void)fireProgressNotification:(CGFloat)progress attachmentId:(NSString *)attachmentId
{
dispatch_async(dispatch_get_main_queue(), ^{
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter postNotificationName:kAttachmentDownloadProgressNotification
object:nil
userInfo:@{
kAttachmentDownloadProgressKey : @(progress),
kAttachmentDownloadAttachmentIDKey : attachmentId
}];
});
}
- (void)setAttachment:(TSAttachmentPointer *)pointer isDownloadingInMessage:(nullable TSMessage *)message
{
pointer.state = TSAttachmentPointerStateDownloading;