pull/122/head
Niels Andriesse 6 years ago
parent 53528184c3
commit 60569bf4c3

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

@ -1133,7 +1133,7 @@ static NSTimeInterval launchStartedAt;
return; return;
} }
CurrentAppContext().isWakenByRemoteNotification = true; CurrentAppContext().wasWokenUpBySilentPushNotification = true;
[LKLogger print:@"[Loki] Silent push notification received; fetching messages."]; [LKLogger print:@"[Loki] Silent push notification received; fetching messages."];
@ -1162,11 +1162,11 @@ static NSTimeInterval launchStartedAt;
PMKJoin(promises).then(^(id results) { PMKJoin(promises).then(^(id results) {
completionHandler(UIBackgroundFetchResultNewData); completionHandler(UIBackgroundFetchResultNewData);
CurrentAppContext().isWakenByRemoteNotification = false; CurrentAppContext().wasWokenUpBySilentPushNotification = false;
[LKLogger print:@"[Loki] UIBackgroundFetchResultNewData"]; [LKLogger print:@"[Loki] UIBackgroundFetchResultNewData"];
}).catch(^(id error) { }).catch(^(id error) {
completionHandler(UIBackgroundFetchResultFailed); completionHandler(UIBackgroundFetchResultFailed);
CurrentAppContext().isWakenByRemoteNotification = false; CurrentAppContext().wasWokenUpBySilentPushNotification = false;
[LKLogger print:@"[Loki] UIBackgroundFetchResultFailed"]; [LKLogger print:@"[Loki] UIBackgroundFetchResultFailed"];
}); });
} }
@ -1599,13 +1599,15 @@ static NSTimeInterval launchStartedAt;
{ {
[self setUpLongPollerIfNeeded]; [self setUpLongPollerIfNeeded];
[self.lokiLongPoller startIfNeeded]; [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]; [LKPublicChatManager.shared startPollersIfNeeded];
[SSKEnvironment.shared.attachmentDownloads startDownloadIfNeeded]; [SSKEnvironment.shared.attachmentDownloads continueDownloadIfPossible];
} }
- (void)stopLongPollerIfNeeded - (void)stopLongPollerIfNeeded
{ {
[self.lokiLongPoller stopIfNeeded]; [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]; [LKPublicChatManager.shared stopPollers];
} }

@ -22,8 +22,11 @@ final class LokiPushNotificationManager : NSObject {
} }
// Send token to Loki server // Send token to Loki server
let parameters = [ "token" : hexEncodedToken ] 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://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) let request = TSRequest(url: url, method: "POST", parameters: parameters)
request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ] request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ]
TSNetworkManager.shared().makeRequest(request, success: { _, response in TSNetworkManager.shared().makeRequest(request, success: { _, response in

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

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

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

@ -37,8 +37,9 @@ NSString *NSStringForUIApplicationState(UIApplicationState value);
@property (nonatomic, readonly) BOOL isMainApp; @property (nonatomic, readonly) BOOL isMainApp;
@property (nonatomic, readonly) BOOL isMainAppAndActive; @property (nonatomic, readonly) BOOL isMainAppAndActive;
//A flag to determine if the attatchment downloading tasks should run /// Whether the app was woken up by a silent push notification. This is important for
@property (nonatomic) BOOL isWakenByRemoteNotification; /// determining whether attachments should be downloaded or not.
@property (nonatomic) BOOL wasWokenUpBySilentPushNotification;
// Whether the user is using a right-to-left language like Arabic. // Whether the user is using a right-to-left language like Arabic.
@property (nonatomic, readonly) BOOL isRTL; @property (nonatomic, readonly) BOOL isRTL;

Loading…
Cancel
Save