fix attachment download

pull/118/head
Ryan ZHAO 5 years ago
parent 5c5cafc427
commit d6f2f6fee2

@ -7,7 +7,7 @@
<key>CarthageVersion</key>
<string>0.34.0</string>
<key>OSXVersion</key>
<string>10.15.3</string>
<string>10.15.2</string>
<key>WebRTCCommit</key>
<string>1445d719bf05280270e9f77576f80f973fd847f8 M73</string>
</dict>

@ -1118,6 +1118,8 @@ static NSTimeInterval launchStartedAt;
OWSLogInfo(@"Ignoring remote notification; app not ready.");
return;
}
CurrentAppContext().isWakenByRemoteNotification = true;
[LKLogger print:@"[Loki] Silent push notification received; fetching messages."];
@ -1135,7 +1137,7 @@ static NSTimeInterval launchStartedAt;
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
publicChats = [LKDatabaseUtilities getAllPublicChats:transaction];
}];
for (LKPublicChat *publicChat in publicChats) {
for (LKPublicChat *publicChat in publicChats.allValues) {
if (![publicChat isKindOfClass:LKPublicChat.class]) { continue; } // For some reason publicChat is sometimes a base 64 encoded string...
LKPublicChatPoller *poller = [[LKPublicChatPoller alloc] initForPublicChat:publicChat];
[poller stop];
@ -1146,8 +1148,12 @@ static NSTimeInterval launchStartedAt;
PMKJoin(promises).then(^(id results) {
completionHandler(UIBackgroundFetchResultNewData);
CurrentAppContext().isWakenByRemoteNotification = false;
[LKLogger print:@"[Loki] UIBackgroundFetchResultNewData"];
}).catch(^(id error) {
completionHandler(UIBackgroundFetchResultFailed);
CurrentAppContext().isWakenByRemoteNotification = false;
[LKLogger print:@"[Loki] UIBackgroundFetchResultFailed"];
});
}
@ -1579,11 +1585,14 @@ static NSTimeInterval launchStartedAt;
{
[self setUpLongPollerIfNeeded];
[self.lokiLongPoller startIfNeeded];
[LKPublicChatManager.shared startPollersIfNeeded];
[SSKEnvironment.shared.attachmentDownloads startDownloadIfNeeded];
}
- (void)stopLongPollerIfNeeded
{
[self.lokiLongPoller stopIfNeeded];
[LKPublicChatManager.shared stopPollers];
}
- (LKRSSFeed *)lokiNewsFeed

@ -21,7 +21,8 @@ final class LokiPushNotificationManager : NSObject {
}
// Send token to Loki server
let parameters = [ "token" : hexEncodedToken ]
let url = URL(string: "https://live.apns.getsession.org/register")!
// let url = URL(string: "https://live.apns.getsession.org/register")!
let url = URL(string: "https://dev.apns.getsession.org/register")!
let request = TSRequest(url: url, method: "POST", parameters: parameters)
request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ]
TSNetworkManager.shared().makeRequest(request, success: { _, response in

@ -28,6 +28,7 @@ NSString *const ReportedApplicationStateDidChangeNotification = @"ReportedApplic
@synthesize mainWindow = _mainWindow;
@synthesize appLaunchTime = _appLaunchTime;
@synthesize isWakenByRemoteNotification = _isWakenByRemoteNotification;
- (instancetype)init
{
@ -40,6 +41,7 @@ NSString *const ReportedApplicationStateDidChangeNotification = @"ReportedApplic
self.reportedApplicationState = UIApplicationStateInactive;
_appLaunchTime = [NSDate new];
_isWakenByRemoteNotification = false;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForeground:)

@ -55,6 +55,7 @@ public final class LokiPublicChatPoller : NSObject {
let publicChat = self.publicChat
let userHexEncodedPublicKey = self.userHexEncodedPublicKey
return LokiPublicChatAPI.getMessages(for: publicChat.channel, on: publicChat.server).done(on: DispatchQueue.global()) { messages in
print("[Loki] Poll for new open group messages, message count \(messages.count)")
let uniqueHexEncodedPublicKeys = Set(messages.map { $0.hexEncodedPublicKey })
func proceed() {
let storage = OWSPrimaryStorage.shared()

@ -43,6 +43,8 @@ extern NSString *const kAttachmentDownloadAttachmentIDKey;
success:(void (^)(NSArray<TSAttachmentStream *> *attachmentStreams))success
failure:(void (^)(NSError *error))failure;
- (void)startDownloadIfNeeded;
@end
NS_ASSUME_NONNULL_END

@ -264,6 +264,8 @@ typedef void (^AttachmentDownloadFailure)(NSError *error);
- (void)startDownloadIfPossible
{
if (CurrentAppContext().isWakenByRemoteNotification) { return; }
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
OWSAttachmentDownloadJob *_Nullable job;
@ -342,6 +344,16 @@ typedef void (^AttachmentDownloadFailure)(NSError *error);
#pragma mark -
- (void)startDownloadIfNeeded
{
if (self.attachmentDownloadJobQueue.count > 0) {
[LKLogger print:@"[Loki] start uncompleted attachment download tasks"];
[self startDownloadIfPossible];
}
}
#pragma mark -
- (void)retrieveAttachmentForJob:(OWSAttachmentDownloadJob *)job
success:(void (^)(TSAttachmentStream *attachmentStream))successHandler
failure:(void (^)(NSError *error))failureHandler

@ -37,6 +37,8 @@ NSString *NSStringForUIApplicationState(UIApplicationState value);
@property (nonatomic, readonly) BOOL isMainApp;
@property (nonatomic, readonly) BOOL isMainAppAndActive;
//A flag to determine if the attatchment downloading tasks should run
@property (nonatomic) BOOL isWakenByRemoteNotification;
// Whether the user is using a right-to-left language like Arabic.
@property (nonatomic, readonly) BOOL isRTL;

Loading…
Cancel
Save