Merge branch 'mkirk/download-progress'
This commit is contained in:
commit
1fe0930740
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -260,6 +268,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue