This commit is contained in:
Niels Andriesse 2020-02-21 10:24:03 +07:00
parent 53528184c3
commit 60569bf4c3
7 changed files with 20 additions and 14 deletions

View File

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

View File

@ -1133,7 +1133,7 @@ static NSTimeInterval launchStartedAt;
return;
}
CurrentAppContext().isWakenByRemoteNotification = true;
CurrentAppContext().wasWokenUpBySilentPushNotification = true;
[LKLogger print:@"[Loki] Silent push notification received; fetching messages."];
@ -1162,11 +1162,11 @@ static NSTimeInterval launchStartedAt;
PMKJoin(promises).then(^(id results) {
completionHandler(UIBackgroundFetchResultNewData);
CurrentAppContext().isWakenByRemoteNotification = false;
CurrentAppContext().wasWokenUpBySilentPushNotification = false;
[LKLogger print:@"[Loki] UIBackgroundFetchResultNewData"];
}).catch(^(id error) {
completionHandler(UIBackgroundFetchResultFailed);
CurrentAppContext().isWakenByRemoteNotification = false;
CurrentAppContext().wasWokenUpBySilentPushNotification = false;
[LKLogger print:@"[Loki] UIBackgroundFetchResultFailed"];
});
}
@ -1599,13 +1599,15 @@ static NSTimeInterval launchStartedAt;
{
[self setUpLongPollerIfNeeded];
[self.lokiLongPoller startIfNeeded];
// FIXME: Let's not mix long polling and public chat polling. Better to separate them out into their own functions.
[LKPublicChatManager.shared startPollersIfNeeded];
[SSKEnvironment.shared.attachmentDownloads startDownloadIfNeeded];
[SSKEnvironment.shared.attachmentDownloads continueDownloadIfPossible];
}
- (void)stopLongPollerIfNeeded
{
[self.lokiLongPoller stopIfNeeded];
// FIXME: Let's not mix long polling and public chat polling. Better to separate them out into their own functions.
[LKPublicChatManager.shared stopPollers];
}

View File

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

View File

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

View File

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

View File

@ -264,7 +264,7 @@ typedef void (^AttachmentDownloadFailure)(NSError *error);
- (void)startDownloadIfPossible
{
if (CurrentAppContext().isWakenByRemoteNotification) { return; }
if (CurrentAppContext().wasWokenUpBySilentPushNotification) { return; }
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
OWSAttachmentDownloadJob *_Nullable job;
@ -344,10 +344,10 @@ typedef void (^AttachmentDownloadFailure)(NSError *error);
#pragma mark -
- (void)startDownloadIfNeeded
- (void)continueDownloadIfPossible
{
if (self.attachmentDownloadJobQueue.count > 0) {
[LKLogger print:@"[Loki] start uncompleted attachment download tasks"];
[LKLogger print:@"[Loki] Continuing unfinished attachment download tasks."];
[self startDownloadIfPossible];
}
}

View File

@ -37,8 +37,9 @@ 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 app was woken up by a silent push notification. This is important for
/// determining whether attachments should be downloaded or not.
@property (nonatomic) BOOL wasWokenUpBySilentPushNotification;
// Whether the user is using a right-to-left language like Arabic.
@property (nonatomic, readonly) BOOL isRTL;