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
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
extern NSString *const kAttachmentDownloadProgressNotification;
|
||||||
|
extern NSString *const kAttachmentDownloadProgressKey;
|
||||||
|
extern NSString *const kAttachmentDownloadAttachmentIDKey;
|
||||||
|
|
||||||
@class TSMessage;
|
@class TSMessage;
|
||||||
@class TSThread;
|
@class TSThread;
|
||||||
@class TSNetworkManager;
|
@class TSNetworkManager;
|
||||||
|
|
|
@ -20,6 +20,14 @@
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
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 ()
|
@interface OWSAttachmentsProcessor ()
|
||||||
|
|
||||||
@property (nonatomic, readonly) TSNetworkManager *networkManager;
|
@property (nonatomic, readonly) TSNetworkManager *networkManager;
|
||||||
|
@ -259,7 +267,10 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
abortDownload();
|
abortDownload();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self fireProgressNotification:MAX(kAttachmentDownloadProgressTheta, progress.fractionCompleted)
|
||||||
|
attachmentId:pointer.uniqueId];
|
||||||
|
|
||||||
// We only need to check the content length header once.
|
// We only need to check the content length header once.
|
||||||
if (hasCheckedContentLength) {
|
if (hasCheckedContentLength) {
|
||||||
return;
|
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
|
- (void)setAttachment:(TSAttachmentPointer *)pointer isDownloadingInMessage:(nullable TSMessage *)message
|
||||||
{
|
{
|
||||||
pointer.state = TSAttachmentPointerStateDownloading;
|
pointer.state = TSAttachmentPointerStateDownloading;
|
||||||
|
|
Loading…
Reference in New Issue