Merge pull request #118 from RyanRory/pn-fix-attachment-issue
Fix background tasks crashing when PN received
This commit is contained in:
commit
53528184c3
|
@ -7,7 +7,7 @@
|
|||
<key>CarthageVersion</key>
|
||||
<string>0.33.0</string>
|
||||
<key>OSXVersion</key>
|
||||
<string>10.15.3</string>
|
||||
<string>10.15.2</string>
|
||||
<key>WebRTCCommit</key>
|
||||
<string>1445d719bf05280270e9f77576f80f973fd847f8 M73</string>
|
||||
</dict>
|
||||
|
|
|
@ -1132,6 +1132,8 @@ static NSTimeInterval launchStartedAt;
|
|||
OWSLogInfo(@"Ignoring remote notification; app not ready.");
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentAppContext().isWakenByRemoteNotification = true;
|
||||
|
||||
[LKLogger print:@"[Loki] Silent push notification received; fetching messages."];
|
||||
|
||||
|
@ -1149,7 +1151,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];
|
||||
|
@ -1160,8 +1162,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"];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1593,11 +1599,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
|
||||
|
|
|
@ -23,6 +23,7 @@ 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://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:)
|
||||
|
|
|
@ -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…
Reference in New Issue