Hook Session's PN setup into Signal's PN setup
This commit is contained in:
parent
026bb4aa45
commit
a971a4f609
|
@ -54,8 +54,8 @@
|
|||
NSString *const AppDelegateStoryboardMain = @"Main";
|
||||
|
||||
static NSString *const kInitialViewControllerIdentifier = @"UserInitialViewController";
|
||||
static NSString *const kURLSchemeSGNLKey = @"sgnl";
|
||||
static NSString *const kURLHostVerifyPrefix = @"verify";
|
||||
static NSString *const kURLSchemeSGNLKey = @"sgnl";
|
||||
static NSString *const kURLHostVerifyPrefix = @"verify";
|
||||
|
||||
static NSTimeInterval launchStartedAt;
|
||||
|
||||
|
@ -177,7 +177,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application
|
||||
{
|
||||
OWSLogInfo(@"applicationDidEnterBackground.");
|
||||
OWSLogInfo(@"applicationDidEnterBackground");
|
||||
|
||||
[DDLog flushLog];
|
||||
|
||||
|
@ -188,17 +188,17 @@ static BOOL isInternalTestVersion = NO;
|
|||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application
|
||||
{
|
||||
OWSLogInfo(@"applicationWillEnterForeground.");
|
||||
OWSLogInfo(@"applicationWillEnterForeground");
|
||||
}
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
|
||||
{
|
||||
OWSLogInfo(@"applicationDidReceiveMemoryWarning.");
|
||||
OWSLogInfo(@"applicationDidReceiveMemoryWarning");
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application
|
||||
{
|
||||
OWSLogInfo(@"applicationWillTerminate.");
|
||||
OWSLogInfo(@"applicationWillTerminate");
|
||||
|
||||
[DDLog flushLog];
|
||||
|
||||
|
@ -229,7 +229,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
[DebugLogger.sharedLogger enableFileLogging];
|
||||
}
|
||||
|
||||
OWSLogWarn(@"application: didFinishLaunchingWithOptions.");
|
||||
OWSLogWarn(@"application:didFinishLaunchingWithOptions");
|
||||
[Cryptography seedRandom];
|
||||
|
||||
// XXX - careful when moving this. It must happen before we initialize OWSPrimaryStorage.
|
||||
|
@ -251,7 +251,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
//
|
||||
// ensureIsReadyForAppExtensions will show a failure mode UI that
|
||||
// lets users report this error.
|
||||
OWSLogInfo(@"application: didFinishLaunchingWithOptions failed.");
|
||||
OWSLogInfo(@"application:didFinishLaunchingWithOptions failed");
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
}
|
||||
|
||||
if (![OWSPrimaryStorage isDatabasePasswordAccessible]) {
|
||||
OWSLogInfo(@"exiting because we are in the background and the database password is not accessible.");
|
||||
OWSLogInfo(@"Exiting because we are in the background and the database password is not accessible.");
|
||||
|
||||
UILocalNotification *notification = [UILocalNotification new];
|
||||
NSString *messageFormat = NSLocalizedString(@"NOTIFICATION_BODY_PHONE_LOCKED_FORMAT",
|
||||
|
@ -451,7 +451,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
}
|
||||
|
||||
if (error) {
|
||||
OWSFailDebug(@"database conversion failed: %@", error);
|
||||
OWSFailDebug(@"Database conversion failed: %@", error);
|
||||
[self showLaunchFailureUI:error];
|
||||
return NO;
|
||||
}
|
||||
|
@ -490,7 +490,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction *_Nonnull action) {
|
||||
[Pastelog submitLogsWithCompletion:^{
|
||||
OWSFail(@"exiting after sharing debug logs.");
|
||||
OWSFail(@"Exiting after sharing debug logs.");
|
||||
}];
|
||||
}]];
|
||||
UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController];
|
||||
|
@ -503,7 +503,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
|
||||
NSString *databaseFilePath = [OWSPrimaryStorage legacyDatabaseFilePath];
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:databaseFilePath]) {
|
||||
OWSLogVerbose(@"no legacy database file found");
|
||||
OWSLogVerbose(@"No legacy database file found");
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -583,11 +583,11 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
return;
|
||||
}
|
||||
|
||||
OWSLogInfo(@"Registered for push notifications with token: %@.", deviceToken);
|
||||
OWSLogInfo(@"Registering for push notifications with token: %@.", deviceToken);
|
||||
BOOL isUsingFullAPNs = [NSUserDefaults.standardUserDefaults boolForKey:@"isUsingFullAPNs"];
|
||||
if (isUsingFullAPNs) {
|
||||
[LKPushNotificationManager registerWithToken:deviceToken hexEncodedPublicKey:self.tsAccountManager.localNumber];
|
||||
|
@ -599,13 +599,13 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
return;
|
||||
}
|
||||
|
||||
OWSLogError(@"failed to register vanilla push token with error: %@", error);
|
||||
OWSLogError(@"Failed to register push token with error: %@.", error);
|
||||
#ifdef DEBUG
|
||||
OWSLogWarn(@"We're in debug mode. Faking success for remote registration with a fake push identifier");
|
||||
OWSLogWarn(@"We're in debug mode. Faking success for remote registration with a fake push identifier.");
|
||||
[self.pushRegistrationManager didReceiveVanillaPushToken:[[NSMutableData dataWithLength:32] copy]];
|
||||
#else
|
||||
OWSProdError([OWSAnalyticsEvents appDelegateErrorFailedToRegisterForRemoteNotifications]);
|
||||
|
@ -619,11 +619,11 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
return;
|
||||
}
|
||||
|
||||
OWSLogInfo(@"registered legacy notification settings");
|
||||
OWSLogInfo(@"Registered legacy notification settings.");
|
||||
[self.notificationPresenter didRegisterLegacyNotificationSettings];
|
||||
}
|
||||
|
||||
|
@ -635,7 +635,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -660,7 +660,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
[verificationView setVerificationCodeAndTryToVerify:verificationCode];
|
||||
return YES;
|
||||
} else {
|
||||
OWSLogWarn(@"Not the verification view controller we expected. Got %@ instead",
|
||||
OWSLogWarn(@"Not the verification view controller we expected. Got %@ instead.",
|
||||
NSStringFromClass(controller.class));
|
||||
}
|
||||
}
|
||||
|
@ -677,11 +677,11 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
return;
|
||||
}
|
||||
|
||||
OWSLogWarn(@"applicationDidBecomeActive.");
|
||||
OWSLogWarn(@"applicationDidBecomeActive");
|
||||
if (CurrentAppContext().isRunningTests) {
|
||||
return;
|
||||
}
|
||||
|
@ -701,7 +701,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
// On every activation, clear old temp directories.
|
||||
ClearOldTemporaryDirectories();
|
||||
|
||||
OWSLogInfo(@"applicationDidBecomeActive completed.");
|
||||
OWSLogInfo(@"applicationDidBecomeActive completed");
|
||||
}
|
||||
|
||||
- (void)enableBackgroundRefreshIfNecessary
|
||||
|
@ -728,7 +728,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
OWSLogWarn(@"handleActivation.");
|
||||
OWSLogWarn(@"handleActivation");
|
||||
|
||||
// Always check prekeys after app launches, and sometimes check on app activation.
|
||||
[TSPreKeyManager checkPreKeysIfNecessary];
|
||||
|
@ -741,7 +741,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
// At this point, potentially lengthy DB locking migrations could be running.
|
||||
// Avoid blocking app launch by putting all further possible DB access in async block
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
OWSLogInfo(@"running post launch block for registered user: %@", [self.tsAccountManager localNumber]);
|
||||
OWSLogInfo(@"Running post launch block for registered user: %@.", [self.tsAccountManager localNumber]);
|
||||
|
||||
// Clean up any messages that expired since last launch immediately
|
||||
// and continue cleaning in the background.
|
||||
|
@ -761,7 +761,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
[[[OWSFailedAttachmentDownloadsJob alloc] initWithPrimaryStorage:self.primaryStorage] run];
|
||||
});
|
||||
} else {
|
||||
OWSLogInfo(@"running post launch block for unregistered user.");
|
||||
OWSLogInfo(@"Running post launch block for unregistered user.");
|
||||
|
||||
// Unregistered user should have no unread messages. e.g. if you delete your account.
|
||||
[AppEnvironment.shared.notificationPresenter clearAllNotifications];
|
||||
|
@ -811,7 +811,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
}
|
||||
|
||||
if (![UIApplication sharedApplication].isRegisteredForRemoteNotifications) {
|
||||
OWSLogInfo(@"Retrying to register for remote notifications since user hasn't registered yet.");
|
||||
OWSLogInfo(@"Retrying remote notification registration since user hasn't registered yet.");
|
||||
// Push tokens don't normally change while the app is launched, so checking once during launch is
|
||||
// usually sufficient, but e.g. on iOS11, users who have disabled "Allow Notifications" and disabled
|
||||
// "Background App Refresh" will not be able to obtain an APN token. Enabling those settings does not
|
||||
|
@ -823,7 +823,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
|
||||
if ([OWS2FAManager sharedManager].isDueForReminder) {
|
||||
if (!self.hasInitialRootViewController || self.window.rootViewController == nil) {
|
||||
OWSLogDebug(@"Skipping 2FA reminder since there isn't yet an initial view controller");
|
||||
OWSLogDebug(@"Skipping 2FA reminder since there isn't yet an initial view controller.");
|
||||
} else {
|
||||
UIViewController *rootViewController = self.window.rootViewController;
|
||||
OWSNavigationController *reminderNavController =
|
||||
|
@ -835,7 +835,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
});
|
||||
}
|
||||
|
||||
OWSLogInfo(@"handleActivation completed.");
|
||||
OWSLogInfo(@"handleActivation completed");
|
||||
}
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application
|
||||
|
@ -843,11 +843,11 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
return;
|
||||
}
|
||||
|
||||
OWSLogWarn(@"applicationWillResignActive.");
|
||||
OWSLogWarn(@"applicationWillResignActive");
|
||||
|
||||
[self clearAllNotificationsAndRestoreBadgeCount];
|
||||
|
||||
|
@ -870,7 +870,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
completionHandler(NO);
|
||||
return;
|
||||
}
|
||||
|
@ -902,197 +902,13 @@ static BOOL isInternalTestVersion = NO;
|
|||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Among other things, this is used by "call back" callkit dialog and calling from native contacts app.
|
||||
*
|
||||
* We always return YES if we are going to try to handle the user activity since
|
||||
* we never want iOS to contact us again using a URL.
|
||||
*
|
||||
* From https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623072-application?language=objc:
|
||||
*
|
||||
* If you do not implement this method or if your implementation returns NO, iOS tries to
|
||||
* create a document for your app to open using a URL.
|
||||
*/
|
||||
- (BOOL)application:(UIApplication *)application
|
||||
continueUserActivity:(nonnull NSUserActivity *)userActivity
|
||||
restorationHandler:(nonnull void (^)(NSArray *_Nullable))restorationHandler
|
||||
{
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ([userActivity.activityType isEqualToString:@"INStartVideoCallIntent"]) {
|
||||
if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(10, 0)) {
|
||||
OWSLogError(@"unexpectedly received INStartVideoCallIntent pre iOS10");
|
||||
return NO;
|
||||
}
|
||||
|
||||
OWSLogInfo(@"got start video call intent");
|
||||
|
||||
INInteraction *interaction = [userActivity interaction];
|
||||
INIntent *intent = interaction.intent;
|
||||
|
||||
if (![intent isKindOfClass:[INStartVideoCallIntent class]]) {
|
||||
OWSLogError(@"unexpected class for start call video: %@", intent);
|
||||
return NO;
|
||||
}
|
||||
INStartVideoCallIntent *startCallIntent = (INStartVideoCallIntent *)intent;
|
||||
NSString *_Nullable handle = startCallIntent.contacts.firstObject.personHandle.value;
|
||||
if (!handle) {
|
||||
OWSLogWarn(@"unable to find handle in startCallIntent: %@", startCallIntent);
|
||||
return NO;
|
||||
}
|
||||
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
if (![self.tsAccountManager isRegisteredAndReady]) {
|
||||
OWSLogInfo(@"Ignoring user activity; app not ready.");
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *_Nullable phoneNumber = [self phoneNumberForIntentHandle:handle];
|
||||
if (phoneNumber.length < 1) {
|
||||
OWSLogWarn(@"ignoring attempt to initiate video call to unknown user.");
|
||||
return;
|
||||
}
|
||||
|
||||
// This intent can be received from more than one user interaction.
|
||||
//
|
||||
// * It can be received if the user taps the "video" button in the CallKit UI for an
|
||||
// an ongoing call. If so, the correct response is to try to activate the local
|
||||
// video for that call.
|
||||
// * It can be received if the user taps the "video" button for a contact in the
|
||||
// contacts app. If so, the correct response is to try to initiate a new call
|
||||
// to that user - unless there already is another call in progress.
|
||||
// if (AppEnvironment.shared.callService.call != nil) {
|
||||
// if ([phoneNumber isEqualToString:AppEnvironment.shared.callService.call.remotePhoneNumber]) {
|
||||
// OWSLogWarn(@"trying to upgrade ongoing call to video.");
|
||||
// [AppEnvironment.shared.callService handleCallKitStartVideo];
|
||||
// return;
|
||||
// } else {
|
||||
// OWSLogWarn(@"ignoring INStartVideoCallIntent due to ongoing WebRTC call with another party.");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// OutboundCallInitiator *outboundCallInitiator = AppEnvironment.shared.outboundCallInitiator;
|
||||
// OWSAssertDebug(outboundCallInitiator);
|
||||
// [outboundCallInitiator initiateCallWithHandle:phoneNumber];
|
||||
}];
|
||||
return YES;
|
||||
} else if ([userActivity.activityType isEqualToString:@"INStartAudioCallIntent"]) {
|
||||
|
||||
if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(10, 0)) {
|
||||
OWSLogError(@"unexpectedly received INStartAudioCallIntent pre iOS10");
|
||||
return NO;
|
||||
}
|
||||
|
||||
OWSLogInfo(@"got start audio call intent");
|
||||
|
||||
INInteraction *interaction = [userActivity interaction];
|
||||
INIntent *intent = interaction.intent;
|
||||
|
||||
if (![intent isKindOfClass:[INStartAudioCallIntent class]]) {
|
||||
OWSLogError(@"unexpected class for start call audio: %@", intent);
|
||||
return NO;
|
||||
}
|
||||
INStartAudioCallIntent *startCallIntent = (INStartAudioCallIntent *)intent;
|
||||
NSString *_Nullable handle = startCallIntent.contacts.firstObject.personHandle.value;
|
||||
if (!handle) {
|
||||
OWSLogWarn(@"unable to find handle in startCallIntent: %@", startCallIntent);
|
||||
return NO;
|
||||
}
|
||||
|
||||
[AppReadiness runNowOrWhenAppDidBecomeReady:^{
|
||||
if (![self.tsAccountManager isRegisteredAndReady]) {
|
||||
OWSLogInfo(@"Ignoring user activity; app not ready.");
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *_Nullable phoneNumber = [self phoneNumberForIntentHandle:handle];
|
||||
if (phoneNumber.length < 1) {
|
||||
OWSLogWarn(@"ignoring attempt to initiate audio call to unknown user.");
|
||||
return;
|
||||
}
|
||||
|
||||
// if (AppEnvironment.shared.callService.call != nil) {
|
||||
// OWSLogWarn(@"ignoring INStartAudioCallIntent due to ongoing WebRTC call.");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// OutboundCallInitiator *outboundCallInitiator = AppEnvironment.shared.outboundCallInitiator;
|
||||
// OWSAssertDebug(outboundCallInitiator);
|
||||
// [outboundCallInitiator initiateCallWithHandle:phoneNumber];
|
||||
}];
|
||||
return YES;
|
||||
} else {
|
||||
OWSLogWarn(@"userActivity: %@, but not yet supported.", userActivity.activityType);
|
||||
}
|
||||
|
||||
// TODO Something like...
|
||||
// *phoneNumber = [[[[[[userActivity interaction] intent] contacts] firstObject] personHandle] value]
|
||||
// thread = blah
|
||||
// [callUIAdapter startCall:thread]
|
||||
//
|
||||
// Here's the Speakerbox Example for intent / NSUserActivity handling:
|
||||
//
|
||||
// func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
|
||||
// guard let handle = userActivity.startCallHandle else {
|
||||
// print("Could not determine start call handle from user activity: \(userActivity)")
|
||||
// return false
|
||||
// }
|
||||
//
|
||||
// guard let video = userActivity.video else {
|
||||
// print("Could not determine video from user activity: \(userActivity)")
|
||||
// return false
|
||||
// }
|
||||
//
|
||||
// callManager.startCall(handle: handle, video: video)
|
||||
// return true
|
||||
// }
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (nullable NSString *)phoneNumberForIntentHandle:(NSString *)handle
|
||||
{
|
||||
// OWSAssertDebug(handle.length > 0);
|
||||
//
|
||||
// if ([handle hasPrefix:CallKitCallManager.kAnonymousCallHandlePrefix]) {
|
||||
// NSString *_Nullable phoneNumber = [self.primaryStorage phoneNumberForCallKitId:handle];
|
||||
// if (phoneNumber.length < 1) {
|
||||
// OWSLogWarn(@"ignoring attempt to initiate audio call to unknown anonymous signal user.");
|
||||
// return nil;
|
||||
// }
|
||||
// return phoneNumber;
|
||||
// }
|
||||
//
|
||||
// for (PhoneNumber *phoneNumber in
|
||||
// [PhoneNumber tryParsePhoneNumbersFromsUserSpecifiedText:handle
|
||||
// clientPhoneNumber:[TSAccountManager localNumber]]) {
|
||||
// return phoneNumber.toE164;
|
||||
// }
|
||||
return nil;
|
||||
}
|
||||
|
||||
#pragma mark - Orientation
|
||||
|
||||
- (UIInterfaceOrientationMask)application:(UIApplication *)application
|
||||
supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
|
||||
{
|
||||
if (self.hasCall) {
|
||||
OWSLogInfo(@"has call");
|
||||
// The call-banner window is only suitable for portrait display
|
||||
return UIInterfaceOrientationMaskPortrait;
|
||||
}
|
||||
|
||||
UIViewController *_Nullable rootViewController = self.window.rootViewController;
|
||||
if (!rootViewController) {
|
||||
return UIInterfaceOrientationMaskAllButUpsideDown;
|
||||
}
|
||||
return rootViewController.supportedInterfaceOrientations;
|
||||
return UIInterfaceOrientationMaskPortrait;
|
||||
}
|
||||
|
||||
- (BOOL)hasCall
|
||||
|
@ -1106,7 +922,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
return;
|
||||
}
|
||||
if (!(AppReadiness.isAppReady && [self.tsAccountManager isRegisteredAndReady])) {
|
||||
|
@ -1128,7 +944,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
publicChats = [LKDatabaseUtilities getAllPublicChats:transaction];
|
||||
}];
|
||||
for (LKPublicChat *publicChat in publicChats) {
|
||||
if (![publicChat isKindOfClass:LKPublicChat.class]) { continue; } // For some reason publicChat is sometimes a base 64 encoded string...
|
||||
if (![publicChat isKindOfClass:LKPublicChat.class]) { continue; }
|
||||
LKPublicChatPoller *poller = [[LKPublicChatPoller alloc] initForPublicChat:publicChat];
|
||||
[poller stop];
|
||||
AnyPromise *fetchGroupMessagesPromise = [poller pollForNewMessages];
|
||||
|
@ -1142,7 +958,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
return;
|
||||
}
|
||||
if (!(AppReadiness.isAppReady && [self.tsAccountManager isRegisteredAndReady])) {
|
||||
|
@ -1190,7 +1006,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1218,7 +1034,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
completionHandler();
|
||||
return;
|
||||
}
|
||||
|
@ -1249,12 +1065,12 @@ static BOOL isInternalTestVersion = NO;
|
|||
withResponseInfo:(NSDictionary *)responseInfo
|
||||
completionHandler:(void (^)())completionHandler
|
||||
{
|
||||
OWSLogInfo(@"handling action with identifier: %@", identifier);
|
||||
OWSLogInfo(@"Handling action with identifier: %@", identifier);
|
||||
|
||||
OWSAssertIsOnMainThread();
|
||||
|
||||
if (self.didAppLaunchFail) {
|
||||
OWSFailDebug(@"app launch failed");
|
||||
OWSFailDebug(@"App launch failed");
|
||||
completionHandler();
|
||||
return;
|
||||
}
|
||||
|
@ -1367,7 +1183,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
if ([self.tsAccountManager isRegistered]) {
|
||||
OWSLogInfo(@"localNumber: %@", [TSAccountManager localNumber]);
|
||||
|
||||
// This should happen at any launch, background or foreground.
|
||||
// This should happen at any launch, background or foreground
|
||||
__unused AnyPromise *pushTokenpromise =
|
||||
[OWSSyncPushTokensJob runWithAccountManager:AppEnvironment.shared.accountManager
|
||||
preferences:Environment.shared.preferences];
|
||||
|
@ -1468,6 +1284,7 @@ static BOOL isInternalTestVersion = NO;
|
|||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[ExperienceUpgradeFinder.sharedManager markAllAsSeenWithTransaction:transaction];
|
||||
}];
|
||||
|
||||
// Start running the disappearing messages job in case the newly registered user
|
||||
// enables this feature
|
||||
[self.disappearingMessagesJob startIfNecessary];
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import PromiseKit
|
||||
|
||||
final class PNModeVC : BaseVC, OptionViewDelegate {
|
||||
|
||||
|
@ -10,7 +11,7 @@ final class PNModeVC : BaseVC, OptionViewDelegate {
|
|||
}
|
||||
|
||||
// MARK: Components
|
||||
private lazy var apnsOptionView = OptionView(title: "Apple Push Notification Service", explanation: "The app will use the Apple Push Notification Service. You'll be notified of new messages immediately. This mode entails a slight privacy sacrifice as Apple will know your IP. The contents of your messages will still be fully encrypted, your data will still be stored in a decentralized manner and your messages will still be onion routed.", delegate: self)
|
||||
private lazy var apnsOptionView = OptionView(title: "Apple Push Notification Service", explanation: "The app will use the Apple Push Notification Service. You'll be notified of new messages immediately. This mode entails a slight privacy sacrifice as Apple will know your IP. The contents of your messages will still be fully encrypted, your data will still be stored in a decentralized manner and your messages will still be onion routed.", delegate: self, isRecommended: true)
|
||||
private lazy var backgroundPollingOptionView = OptionView(title: "Background Polling", explanation: "The app will occassionally check for new messages when it's in the background. This provides full privacy but notifications may be significantly delayed.", delegate: self)
|
||||
private lazy var noPNsOptionView = OptionView(title: "No Push Notifications", explanation: "You will not be notified of new messages when the app is closed. This provides full privacy.", delegate: self)
|
||||
|
||||
|
@ -97,6 +98,9 @@ final class PNModeVC : BaseVC, OptionViewDelegate {
|
|||
TSAccountManager.sharedInstance().didRegister()
|
||||
let homeVC = HomeVC()
|
||||
navigationController!.setViewControllers([ homeVC ], animated: true)
|
||||
if (selectedOptionView == apnsOptionView || selectedOptionView == backgroundPollingOptionView) {
|
||||
let _: Promise<Void> = SyncPushTokensJob.run(accountManager: AppEnvironment.shared.accountManager, preferences: Environment.shared.preferences)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,12 +111,14 @@ private extension PNModeVC {
|
|||
private let title: String
|
||||
private let explanation: String
|
||||
private let delegate: OptionViewDelegate
|
||||
private let isRecommended: Bool
|
||||
var isSelected = false { didSet { handleIsSelectedChanged() } }
|
||||
|
||||
init(title: String, explanation: String, delegate: OptionViewDelegate) {
|
||||
init(title: String, explanation: String, delegate: OptionViewDelegate, isRecommended: Bool = false) {
|
||||
self.title = title
|
||||
self.explanation = explanation
|
||||
self.delegate = delegate
|
||||
self.isRecommended = isRecommended
|
||||
super.init(frame: CGRect.zero)
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
@ -160,6 +166,14 @@ private extension PNModeVC {
|
|||
stackView.pin(.top, to: .top, of: self, withInset: 12)
|
||||
self.pin(.trailing, to: .trailing, of: stackView, withInset: 12)
|
||||
self.pin(.bottom, to: .bottom, of: stackView, withInset: 12)
|
||||
// Set up recommended label if needed
|
||||
if isRecommended {
|
||||
let recommendedLabel = UILabel()
|
||||
recommendedLabel.textColor = Colors.accent
|
||||
recommendedLabel.font = .boldSystemFont(ofSize: Values.verySmallFontSize)
|
||||
recommendedLabel.text = "*Recommended"
|
||||
stackView.addArrangedSubview(recommendedLabel)
|
||||
}
|
||||
// Set up tap gesture recognizer
|
||||
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap))
|
||||
addGestureRecognizer(tapGestureRecognizer)
|
||||
|
|
|
@ -296,13 +296,13 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
failure:(void (^)(NSError *))failureHandler
|
||||
remainingRetries:(int)remainingRetries
|
||||
{
|
||||
TSRequest *request =
|
||||
[OWSRequestFactory registerForPushRequestWithPushIdentifier:pushToken voipIdentifier:voipToken];
|
||||
[self.networkManager makeRequest:request
|
||||
success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
BOOL isUsingFullAPNs = [NSUserDefaults.standardUserDefaults boolForKey:@"isUsingFullAPNs"];
|
||||
if (isUsingFullAPNs) {
|
||||
[LKPushNotificationManager registerWithToken:pushToken hexEncodedPublicKey:self.localNumber]
|
||||
.then(^() {
|
||||
successHandler();
|
||||
}
|
||||
failure:^(NSURLSessionDataTask *task, NSError *error) {
|
||||
})
|
||||
.catch(^(NSError *error) {
|
||||
if (remainingRetries > 0) {
|
||||
[self registerForPushNotificationsWithPushToken:pushToken
|
||||
voipToken:voipToken
|
||||
|
@ -315,7 +315,8 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
}
|
||||
failureHandler(error);
|
||||
}
|
||||
}];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
- (void)registerWithPhoneNumber:(NSString *)phoneNumber
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import PromiseKit
|
||||
|
||||
@objc(LKPushNotificationManager)
|
||||
final class LokiPushNotificationManager : NSObject {
|
||||
|
@ -51,8 +52,7 @@ final class LokiPushNotificationManager : NSObject {
|
|||
|
||||
/// Registers the user for normal push notifications. Requires the user's device
|
||||
/// token and their Session ID.
|
||||
@objc(registerWithToken:hexEncodedPublicKey:)
|
||||
static func register(with token: Data, hexEncodedPublicKey: String) {
|
||||
static func register(with token: Data, hexEncodedPublicKey: String) -> Promise<Void> {
|
||||
let hexEncodedToken = token.toHexString()
|
||||
let userDefaults = UserDefaults.standard
|
||||
let now = Date().timeIntervalSince1970
|
||||
|
@ -60,7 +60,7 @@ final class LokiPushNotificationManager : NSObject {
|
|||
let url = URL(string: server + "register")!
|
||||
let request = TSRequest(url: url, method: "POST", parameters: parameters)
|
||||
request.allHTTPHeaderFields = [ "Content-Type" : "application/json" ]
|
||||
TSNetworkManager.shared().makeRequest(request, success: { _, response in
|
||||
let promise = TSNetworkManager.shared().makePromise(request: request).map { _, response in
|
||||
guard let json = response as? JSON else {
|
||||
return print("[Loki] Couldn't register device token.")
|
||||
}
|
||||
|
@ -70,9 +70,17 @@ final class LokiPushNotificationManager : NSObject {
|
|||
userDefaults[.deviceToken] = hexEncodedToken
|
||||
userDefaults[.lastDeviceTokenUpload] = now
|
||||
userDefaults[.isUsingFullAPNs] = true
|
||||
}, failure: { _, error in
|
||||
return
|
||||
}
|
||||
promise.catch { error in
|
||||
print("[Loki] Couldn't register device token.")
|
||||
})
|
||||
}
|
||||
return promise
|
||||
}
|
||||
|
||||
@objc(registerWithToken:hexEncodedPublicKey:)
|
||||
static func objc_register(with token: Data, hexEncodedPublicKey: String) -> AnyPromise {
|
||||
return AnyPromise.from(register(with: token, hexEncodedPublicKey: hexEncodedPublicKey))
|
||||
}
|
||||
|
||||
@objc(acknowledgeDeliveryForMessageWithHash:expiration:hexEncodedPublicKey:)
|
||||
|
|
Loading…
Reference in New Issue