mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Rework push registration
== Account Registration == Not complete until push tokens are uploaded == Remote Notifications Registration == Extracted from PushManager - wait for notification-settings registration to complete before requesting push tokens, otherwise it's possible token requests will be ignored. - Less state required for push notification callbacks, specifically, we no longer need to ensure we've created a promise before the registration delegate methods get called. - no more TOCFuture in Signal-iOS (still in SSK for now). It's not in cases of inexplicable behavior - one a recently, push notification premature free, in redphone, and more popular use, and I've seen two futures inexplicably being nil. Instead, let's consolidate around PromiseKit for popularly used, maintained, strongly-typed futures. - separate logic for registering for vanilla push/voip notifications (few dependencies) from responding to UILocalNotifications (lots of dependencies). Ultimately I'd like to consolidate the remaining UILocalNotifications logic with the existing NotificationsManager == Misc == more debug logging more uniform logging remove stale logic around newly registered user // FREEBIE
This commit is contained in:
parent
b916e14abc
commit
df15c904bc
18 changed files with 335 additions and 256 deletions
|
@ -156,6 +156,8 @@
|
||||||
452ECA4E1E087E7200E2F016 /* MessageFetcherJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 452ECA4C1E087E7200E2F016 /* MessageFetcherJob.swift */; };
|
452ECA4E1E087E7200E2F016 /* MessageFetcherJob.swift in Sources */ = {isa = PBXBuildFile; fileRef = 452ECA4C1E087E7200E2F016 /* MessageFetcherJob.swift */; };
|
||||||
4531C9C41DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 4531C9C31DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m */; };
|
4531C9C41DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 4531C9C31DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m */; };
|
||||||
45387B041E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 45387B031E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m */; };
|
45387B041E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 45387B031E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m */; };
|
||||||
|
4539B5861F79348F007141FF /* PushRegistrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4539B5851F79348F007141FF /* PushRegistrationManager.swift */; };
|
||||||
|
4539B5871F79348F007141FF /* PushRegistrationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4539B5851F79348F007141FF /* PushRegistrationManager.swift */; };
|
||||||
453D28BA1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */; };
|
453D28BA1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */; };
|
||||||
453D28BB1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */; };
|
453D28BB1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */; };
|
||||||
4542F0941EB9372700C7EE92 /* SystemContactsFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4542F0931EB9372700C7EE92 /* SystemContactsFetcher.swift */; };
|
4542F0941EB9372700C7EE92 /* SystemContactsFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4542F0931EB9372700C7EE92 /* SystemContactsFetcher.swift */; };
|
||||||
|
@ -303,7 +305,6 @@
|
||||||
B6258B331C29E2E60014138E /* NotificationsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B6258B321C29E2E60014138E /* NotificationsManager.m */; };
|
B6258B331C29E2E60014138E /* NotificationsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = B6258B321C29E2E60014138E /* NotificationsManager.m */; };
|
||||||
B625CD561ABB589C00E8B23C /* NewMessage.aifc in Resources */ = {isa = PBXBuildFile; fileRef = B625CD551ABB589C00E8B23C /* NewMessage.aifc */; };
|
B625CD561ABB589C00E8B23C /* NewMessage.aifc in Resources */ = {isa = PBXBuildFile; fileRef = B625CD551ABB589C00E8B23C /* NewMessage.aifc */; };
|
||||||
B62D53F71A23CCAD009AAF82 /* TSMessageAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = B62D53F61A23CCAD009AAF82 /* TSMessageAdapter.m */; };
|
B62D53F71A23CCAD009AAF82 /* TSMessageAdapter.m in Sources */ = {isa = PBXBuildFile; fileRef = B62D53F61A23CCAD009AAF82 /* TSMessageAdapter.m */; };
|
||||||
B62F5E101C2980B4000D370C /* NSData+ows_StripToken.m in Sources */ = {isa = PBXBuildFile; fileRef = B62F5E0F1C2980B4000D370C /* NSData+ows_StripToken.m */; };
|
|
||||||
B633C5861A1D190B0059AC12 /* call@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B633C5041A1D190B0059AC12 /* call@2x.png */; };
|
B633C5861A1D190B0059AC12 /* call@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B633C5041A1D190B0059AC12 /* call@2x.png */; };
|
||||||
B633C58D1A1D190B0059AC12 /* contact_default_feed.png in Resources */ = {isa = PBXBuildFile; fileRef = B633C50B1A1D190B0059AC12 /* contact_default_feed.png */; };
|
B633C58D1A1D190B0059AC12 /* contact_default_feed.png in Resources */ = {isa = PBXBuildFile; fileRef = B633C50B1A1D190B0059AC12 /* contact_default_feed.png */; };
|
||||||
B633C59D1A1D190B0059AC12 /* endcall@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B633C51B1A1D190B0059AC12 /* endcall@2x.png */; };
|
B633C59D1A1D190B0059AC12 /* endcall@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B633C51B1A1D190B0059AC12 /* endcall@2x.png */; };
|
||||||
|
@ -625,6 +626,7 @@
|
||||||
4531C9C31DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSQMessagesCollectionViewCell+OWS.m"; sourceTree = "<group>"; };
|
4531C9C31DD8E6D800F08304 /* JSQMessagesCollectionViewCell+OWS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "JSQMessagesCollectionViewCell+OWS.m"; sourceTree = "<group>"; };
|
||||||
45387B021E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWS102MoveLoggingPreferenceToUserDefaults.h; path = Migrations/OWS102MoveLoggingPreferenceToUserDefaults.h; sourceTree = "<group>"; };
|
45387B021E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWS102MoveLoggingPreferenceToUserDefaults.h; path = Migrations/OWS102MoveLoggingPreferenceToUserDefaults.h; sourceTree = "<group>"; };
|
||||||
45387B031E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWS102MoveLoggingPreferenceToUserDefaults.m; path = Migrations/OWS102MoveLoggingPreferenceToUserDefaults.m; sourceTree = "<group>"; };
|
45387B031E36D650005D00B3 /* OWS102MoveLoggingPreferenceToUserDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWS102MoveLoggingPreferenceToUserDefaults.m; path = Migrations/OWS102MoveLoggingPreferenceToUserDefaults.m; sourceTree = "<group>"; };
|
||||||
|
4539B5851F79348F007141FF /* PushRegistrationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushRegistrationManager.swift; sourceTree = "<group>"; };
|
||||||
453CC0361D08E1A60040EBA3 /* sn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sn; path = translations/sn.lproj/Localizable.strings; sourceTree = "<group>"; };
|
453CC0361D08E1A60040EBA3 /* sn */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = sn; path = translations/sn.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||||
453D28B81D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessagesBubblesSizeCalculator.h; sourceTree = "<group>"; };
|
453D28B81D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessagesBubblesSizeCalculator.h; sourceTree = "<group>"; };
|
||||||
453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = OWSMessagesBubblesSizeCalculator.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = OWSMessagesBubblesSizeCalculator.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
||||||
|
@ -786,8 +788,6 @@
|
||||||
B625CD551ABB589C00E8B23C /* NewMessage.aifc */ = {isa = PBXFileReference; lastKnownFileType = file; path = NewMessage.aifc; sourceTree = "<group>"; };
|
B625CD551ABB589C00E8B23C /* NewMessage.aifc */ = {isa = PBXFileReference; lastKnownFileType = file; path = NewMessage.aifc; sourceTree = "<group>"; };
|
||||||
B62D53F51A23CCAD009AAF82 /* TSMessageAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSMessageAdapter.h; sourceTree = "<group>"; };
|
B62D53F51A23CCAD009AAF82 /* TSMessageAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSMessageAdapter.h; sourceTree = "<group>"; };
|
||||||
B62D53F61A23CCAD009AAF82 /* TSMessageAdapter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSMessageAdapter.m; sourceTree = "<group>"; };
|
B62D53F61A23CCAD009AAF82 /* TSMessageAdapter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSMessageAdapter.m; sourceTree = "<group>"; };
|
||||||
B62F5E0E1C2980B4000D370C /* NSData+ows_StripToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+ows_StripToken.h"; sourceTree = "<group>"; };
|
|
||||||
B62F5E0F1C2980B4000D370C /* NSData+ows_StripToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+ows_StripToken.m"; sourceTree = "<group>"; };
|
|
||||||
B633C5041A1D190B0059AC12 /* call@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "call@2x.png"; sourceTree = "<group>"; };
|
B633C5041A1D190B0059AC12 /* call@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "call@2x.png"; sourceTree = "<group>"; };
|
||||||
B633C50B1A1D190B0059AC12 /* contact_default_feed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = contact_default_feed.png; sourceTree = "<group>"; };
|
B633C50B1A1D190B0059AC12 /* contact_default_feed.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = contact_default_feed.png; sourceTree = "<group>"; };
|
||||||
B633C51B1A1D190B0059AC12 /* endcall@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "endcall@2x.png"; sourceTree = "<group>"; };
|
B633C51B1A1D190B0059AC12 /* endcall@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "endcall@2x.png"; sourceTree = "<group>"; };
|
||||||
|
@ -1415,6 +1415,7 @@
|
||||||
B6B1013B196D213F007E3930 /* SignalKeyingStorage.m */,
|
B6B1013B196D213F007E3930 /* SignalKeyingStorage.m */,
|
||||||
B60C16631988999D00E97A6C /* VersionMigrations.h */,
|
B60C16631988999D00E97A6C /* VersionMigrations.h */,
|
||||||
B60C16641988999D00E97A6C /* VersionMigrations.m */,
|
B60C16641988999D00E97A6C /* VersionMigrations.m */,
|
||||||
|
4539B5851F79348F007141FF /* PushRegistrationManager.swift */,
|
||||||
);
|
);
|
||||||
path = environment;
|
path = environment;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
@ -1446,8 +1447,6 @@
|
||||||
455AC69A1F4F79E500134004 /* ImageCache.swift */,
|
455AC69A1F4F79E500134004 /* ImageCache.swift */,
|
||||||
34CA1C231F706B5400E51C51 /* NSAttributedString+OWS.h */,
|
34CA1C231F706B5400E51C51 /* NSAttributedString+OWS.h */,
|
||||||
34CA1C241F706B5400E51C51 /* NSAttributedString+OWS.m */,
|
34CA1C241F706B5400E51C51 /* NSAttributedString+OWS.m */,
|
||||||
B62F5E0E1C2980B4000D370C /* NSData+ows_StripToken.h */,
|
|
||||||
B62F5E0F1C2980B4000D370C /* NSData+ows_StripToken.m */,
|
|
||||||
76EB04EC18170B33006006FC /* NumberUtil.h */,
|
76EB04EC18170B33006006FC /* NumberUtil.h */,
|
||||||
76EB04ED18170B33006006FC /* NumberUtil.m */,
|
76EB04ED18170B33006006FC /* NumberUtil.m */,
|
||||||
76EB04EE18170B33006006FC /* Operation.h */,
|
76EB04EE18170B33006006FC /* Operation.h */,
|
||||||
|
@ -2351,6 +2350,7 @@
|
||||||
7038632718F70C0700D4A43F /* CryptoTools.m in Sources */,
|
7038632718F70C0700D4A43F /* CryptoTools.m in Sources */,
|
||||||
45FBC5C81DF8575700E9B410 /* CallKitCallManager.swift in Sources */,
|
45FBC5C81DF8575700E9B410 /* CallKitCallManager.swift in Sources */,
|
||||||
34B3F8911E8DF1710035BE1A /* ShowGroupMembersViewController.m in Sources */,
|
34B3F8911E8DF1710035BE1A /* ShowGroupMembersViewController.m in Sources */,
|
||||||
|
4539B5861F79348F007141FF /* PushRegistrationManager.swift in Sources */,
|
||||||
45FBC5D11DF8592E00E9B410 /* SignalCall.swift in Sources */,
|
45FBC5D11DF8592E00E9B410 /* SignalCall.swift in Sources */,
|
||||||
452C468F1E427E200087B011 /* OutboundCallInitiator.swift in Sources */,
|
452C468F1E427E200087B011 /* OutboundCallInitiator.swift in Sources */,
|
||||||
45F170BB1E2FC5D3003FC1F2 /* CallAudioService.swift in Sources */,
|
45F170BB1E2FC5D3003FC1F2 /* CallAudioService.swift in Sources */,
|
||||||
|
@ -2390,7 +2390,6 @@
|
||||||
34B3F87E1E8DF1700035BE1A /* InboxTableViewCell.m in Sources */,
|
34B3F87E1E8DF1700035BE1A /* InboxTableViewCell.m in Sources */,
|
||||||
34B3F8731E8DF1700035BE1A /* AttachmentApprovalViewController.swift in Sources */,
|
34B3F8731E8DF1700035BE1A /* AttachmentApprovalViewController.swift in Sources */,
|
||||||
B6B1013C196D213F007E3930 /* SignalKeyingStorage.m in Sources */,
|
B6B1013C196D213F007E3930 /* SignalKeyingStorage.m in Sources */,
|
||||||
B62F5E101C2980B4000D370C /* NSData+ows_StripToken.m in Sources */,
|
|
||||||
34D5CC961EA6AFAD005515DB /* OWSContactsSyncing.m in Sources */,
|
34D5CC961EA6AFAD005515DB /* OWSContactsSyncing.m in Sources */,
|
||||||
45E2E9201E153B3D00457AA0 /* Strings.swift in Sources */,
|
45E2E9201E153B3D00457AA0 /* Strings.swift in Sources */,
|
||||||
34B3F88B1E8DF1700035BE1A /* OWSLinkedDevicesTableViewController.m in Sources */,
|
34B3F88B1E8DF1700035BE1A /* OWSLinkedDevicesTableViewController.m in Sources */,
|
||||||
|
@ -2448,6 +2447,7 @@
|
||||||
45F170AF1E2F0393003FC1F2 /* CallAudioSessionTest.swift in Sources */,
|
45F170AF1E2F0393003FC1F2 /* CallAudioSessionTest.swift in Sources */,
|
||||||
34B3F8991E8DF1B90035BE1A /* TSMessageAdapterTest.m in Sources */,
|
34B3F8991E8DF1B90035BE1A /* TSMessageAdapterTest.m in Sources */,
|
||||||
456F6E231E24133500FD2210 /* Platform.swift in Sources */,
|
456F6E231E24133500FD2210 /* Platform.swift in Sources */,
|
||||||
|
4539B5871F79348F007141FF /* PushRegistrationManager.swift in Sources */,
|
||||||
4504493A1F45EE7D002D1ADA /* NSString+OWS.m in Sources */,
|
4504493A1F45EE7D002D1ADA /* NSString+OWS.m in Sources */,
|
||||||
45843D201D2236B30013E85A /* OWSContactsSearcher.m in Sources */,
|
45843D201D2236B30013E85A /* OWSContactsSearcher.m in Sources */,
|
||||||
45AE48521E0732D6004D96C2 /* TurnServerInfo.swift in Sources */,
|
45AE48521E0732D6004D96C2 /* TurnServerInfo.swift in Sources */,
|
||||||
|
|
|
@ -124,7 +124,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
||||||
[self setupEnvironment];
|
[self setupEnvironment];
|
||||||
|
|
||||||
[UIUtil applySignalAppearence];
|
[UIUtil applySignalAppearence];
|
||||||
[[PushManager sharedManager] registerPushKitNotificationFuture];
|
|
||||||
|
|
||||||
if (getenv("runningTests_dontStartApp")) {
|
if (getenv("runningTests_dontStartApp")) {
|
||||||
return YES;
|
return YES;
|
||||||
|
@ -272,7 +271,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
||||||
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
|
||||||
{
|
{
|
||||||
DDLogInfo(@"%@ registered vanilla push token: %@", self.tag, deviceToken);
|
DDLogInfo(@"%@ registered vanilla push token: %@", self.tag, deviceToken);
|
||||||
[PushManager.sharedManager.pushNotificationFutureSource trySetResult:deviceToken];
|
[PushRegistrationManager.sharedManager didReceiveVanillaPushToken:deviceToken];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
|
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
|
||||||
|
@ -280,10 +279,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
||||||
DDLogError(@"%@ failed to register vanilla push token with error: %@", self.tag, error);
|
DDLogError(@"%@ failed to register vanilla push token with error: %@", self.tag, error);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
DDLogWarn(@"%@ We're in debug mode. Faking success for remote registration with a fake push identifier", self.tag);
|
DDLogWarn(@"%@ We're in debug mode. Faking success for remote registration with a fake push identifier", self.tag);
|
||||||
[PushManager.sharedManager.pushNotificationFutureSource trySetResult:[[NSMutableData dataWithLength:32] copy]];
|
[PushRegistrationManager.sharedManager didReceiveVanillaPushToken:[[NSMutableData dataWithLength:32] copy]];
|
||||||
#else
|
#else
|
||||||
OWSProdError([OWSAnalyticsEvents appDelegateErrorFailedToRegisterForRemoteNotifications]);
|
OWSProdError([OWSAnalyticsEvents appDelegateErrorFailedToRegisterForRemoteNotifications]);
|
||||||
[PushManager.sharedManager.pushNotificationFutureSource trySetFailure:error];
|
[PushRegistrationManager.sharedManager didFailToReceiveVanillaPushTokenWithError:error];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +290,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
||||||
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
|
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
|
||||||
{
|
{
|
||||||
DDLogInfo(@"%@ registered user notification settings", self.tag);
|
DDLogInfo(@"%@ registered user notification settings", self.tag);
|
||||||
[PushManager.sharedManager.userNotificationFutureSource trySetResult:notificationSettings];
|
[PushRegistrationManager.sharedManager didRegisterUserNotificationSettings];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application
|
- (BOOL)application:(UIApplication *)application
|
||||||
|
@ -813,7 +812,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
||||||
|
|
||||||
- (void)databaseViewRegistrationComplete
|
- (void)databaseViewRegistrationComplete
|
||||||
{
|
{
|
||||||
DDLogInfo(@"databaseViewRegistrationComplete");
|
DDLogInfo(@"%@ databaseViewRegistrationComplete", self.tag);
|
||||||
|
|
||||||
if ([TSAccountManager isRegistered]) {
|
if ([TSAccountManager isRegistered]) {
|
||||||
DDLogInfo(@"localNumber: %@", [TSAccountManager localNumber]);
|
DDLogInfo(@"localNumber: %@", [TSAccountManager localNumber]);
|
||||||
|
@ -824,8 +823,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
||||||
[[Environment getCurrent].messageFetcherJob runAsync];
|
[[Environment getCurrent].messageFetcherJob runAsync];
|
||||||
|
|
||||||
// This should happen at any launch, background or foreground.
|
// This should happen at any launch, background or foreground.
|
||||||
__unused AnyPromise *promise = [OWSSyncPushTokensJob runWithPushManager:[PushManager sharedManager]
|
__unused AnyPromise *promise = [OWSSyncPushTokensJob runWithAccountManager:[Environment getCurrent].accountManager
|
||||||
accountManager:[Environment getCurrent].accountManager
|
|
||||||
preferences:[Environment preferences]];
|
preferences:[Environment preferences]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -873,7 +871,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
|
||||||
|
|
||||||
- (void)ensureRootViewController
|
- (void)ensureRootViewController
|
||||||
{
|
{
|
||||||
DDLogInfo(@"ensureRootViewController");
|
DDLogInfo(@"%@ ensureRootViewController", self.tag);
|
||||||
|
|
||||||
if ([TSDatabaseView hasPendingViewRegistrations] || self.hasInitialRootViewController) {
|
if ([TSDatabaseView hasPendingViewRegistrations] || self.hasInitialRootViewController) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -11,6 +11,7 @@ import PromiseKit
|
||||||
*/
|
*/
|
||||||
class AccountManager: NSObject {
|
class AccountManager: NSObject {
|
||||||
let TAG = "[AccountManager]"
|
let TAG = "[AccountManager]"
|
||||||
|
|
||||||
let textSecureAccountManager: TSAccountManager
|
let textSecureAccountManager: TSAccountManager
|
||||||
let networkManager: TSNetworkManager
|
let networkManager: TSNetworkManager
|
||||||
let preferences: OWSPreferences
|
let preferences: OWSPreferences
|
||||||
|
@ -33,24 +34,22 @@ class AccountManager: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func register(verificationCode: String) -> Promise<Void> {
|
func register(verificationCode: String) -> Promise<Void> {
|
||||||
let registrationPromise = firstly {
|
guard verificationCode.characters.count > 0 else {
|
||||||
Promise { fulfill, reject in
|
|
||||||
if verificationCode.characters.count == 0 {
|
|
||||||
let error = OWSErrorWithCodeDescription(.userError,
|
let error = OWSErrorWithCodeDescription(.userError,
|
||||||
NSLocalizedString("REGISTRATION_ERROR_BLANK_VERIFICATION_CODE",
|
NSLocalizedString("REGISTRATION_ERROR_BLANK_VERIFICATION_CODE",
|
||||||
comment: "alert body during registration"))
|
comment: "alert body during registration"))
|
||||||
reject(error)
|
return Promise(error: error)
|
||||||
}
|
}
|
||||||
fulfill()
|
|
||||||
}
|
Logger.debug("\(self.TAG) registering with signal server")
|
||||||
}.then {
|
let registrationPromise: Promise<Void> = firstly {
|
||||||
Logger.debug("\(self.TAG) verification code looks well formed.")
|
self.registerForTextSecure(verificationCode: verificationCode)
|
||||||
return self.registerForTextSecure(verificationCode: verificationCode)
|
}.then {
|
||||||
}.then {
|
self.syncPushTokens()
|
||||||
return SyncPushTokensJob.run(pushManager: self.pushManager, accountManager: self, preferences: self.preferences)
|
}.then {
|
||||||
}.then {
|
self.completeRegistration()
|
||||||
Logger.debug("\(self.TAG) successfully registered for TextSecure")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registrationPromise.retainUntilComplete()
|
registrationPromise.retainUntilComplete()
|
||||||
|
|
||||||
return registrationPromise
|
return registrationPromise
|
||||||
|
@ -64,6 +63,16 @@ class AccountManager: NSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func syncPushTokens() -> Promise<Void> {
|
||||||
|
Logger.info("\(self.TAG) in \(#function)")
|
||||||
|
return SyncPushTokensJob.run(accountManager: self, preferences: self.preferences)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func completeRegistration() {
|
||||||
|
Logger.info("\(self.TAG) in \(#function)")
|
||||||
|
self.textSecureAccountManager.didRegister()
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Push Tokens
|
// MARK: Push Tokens
|
||||||
|
|
||||||
func updatePushTokens(pushToken: String, voipToken: String) -> Promise<Void> {
|
func updatePushTokens(pushToken: String, voipToken: String) -> Promise<Void> {
|
||||||
|
|
|
@ -2,25 +2,28 @@
|
||||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
|
||||||
import PromiseKit
|
import PromiseKit
|
||||||
|
|
||||||
@objc(OWSSyncPushTokensJob)
|
@objc(OWSSyncPushTokensJob)
|
||||||
class SyncPushTokensJob: NSObject {
|
class SyncPushTokensJob: NSObject {
|
||||||
let TAG = "[SyncPushTokensJob]"
|
let TAG = "[SyncPushTokensJob]"
|
||||||
let pushManager: PushManager
|
|
||||||
|
// MARK: Dependencies
|
||||||
let accountManager: AccountManager
|
let accountManager: AccountManager
|
||||||
let preferences: OWSPreferences
|
let preferences: OWSPreferences
|
||||||
|
var pushRegistrationManager: PushRegistrationManager {
|
||||||
|
return PushRegistrationManager.shared
|
||||||
|
}
|
||||||
|
|
||||||
var uploadOnlyIfStale = true
|
var uploadOnlyIfStale = true
|
||||||
|
|
||||||
required init(pushManager: PushManager, accountManager: AccountManager, preferences: OWSPreferences) {
|
required init(accountManager: AccountManager, preferences: OWSPreferences) {
|
||||||
self.pushManager = pushManager
|
|
||||||
self.accountManager = accountManager
|
self.accountManager = accountManager
|
||||||
self.preferences = preferences
|
self.preferences = preferences
|
||||||
}
|
}
|
||||||
|
|
||||||
class func run(pushManager: PushManager, accountManager: AccountManager, preferences: OWSPreferences) -> Promise<Void> {
|
class func run(accountManager: AccountManager, preferences: OWSPreferences) -> Promise<Void> {
|
||||||
let job = self.init(pushManager: pushManager, accountManager: accountManager, preferences: preferences)
|
let job = self.init(accountManager: accountManager, preferences: preferences)
|
||||||
return job.run()
|
return job.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,42 +31,43 @@ class SyncPushTokensJob: NSObject {
|
||||||
Logger.info("\(TAG) Starting.")
|
Logger.info("\(TAG) Starting.")
|
||||||
|
|
||||||
let runPromise: Promise<Void> = DispatchQueue.main.promise {
|
let runPromise: Promise<Void> = DispatchQueue.main.promise {
|
||||||
// Required to potentially prompt user for notifications settings
|
// HACK: no-op dispatch to work around a bug in PromiseKit/Swift which won't compile
|
||||||
// before `requestPushTokens` will return.
|
// when dispatching complex Promise types. We should eventually be able to delete the
|
||||||
self.pushManager.validateUserNotificationSettings()
|
// following two lines, skipping this no-op dispatch.
|
||||||
|
return
|
||||||
}.then {
|
}.then {
|
||||||
self.requestPushTokens()
|
return self.pushRegistrationManager.requestPushTokens()
|
||||||
}.then { (pushToken: String, voipToken: String) in
|
}.then { (pushToken: String, voipToken: String) in
|
||||||
|
Logger.info("\(self.TAG) finished: requesting push tokens")
|
||||||
var shouldUploadTokens = false
|
var shouldUploadTokens = false
|
||||||
|
|
||||||
if self.preferences.getPushToken() != pushToken || self.preferences.getVoipToken() != voipToken {
|
if self.preferences.getPushToken() != pushToken || self.preferences.getVoipToken() != voipToken {
|
||||||
Logger.debug("\(self.TAG) Push tokens changed.")
|
Logger.debug("\(self.TAG) Push tokens changed.")
|
||||||
shouldUploadTokens = true
|
shouldUploadTokens = true
|
||||||
} else if !self.uploadOnlyIfStale {
|
} else if !self.uploadOnlyIfStale {
|
||||||
Logger.debug("\(self.TAG) Uploading even though tokens didn't change.")
|
Logger.debug("\(self.TAG) Forced uploading, even though tokens didn't change.")
|
||||||
shouldUploadTokens = true
|
shouldUploadTokens = true
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.warn("\(self.TAG) lastAppVersion: \(AppVersion.instance().lastAppVersion), currentAppVersion: \(AppVersion.instance().currentAppVersion)")
|
|
||||||
if AppVersion.instance().lastAppVersion != AppVersion.instance().currentAppVersion {
|
if AppVersion.instance().lastAppVersion != AppVersion.instance().currentAppVersion {
|
||||||
Logger.debug("\(self.TAG) Fresh install or app upgrade.")
|
Logger.info("\(self.TAG) Uploading due to fresh install or app upgrade.")
|
||||||
shouldUploadTokens = true
|
shouldUploadTokens = true
|
||||||
}
|
}
|
||||||
|
|
||||||
guard shouldUploadTokens else {
|
guard shouldUploadTokens else {
|
||||||
Logger.warn("\(self.TAG) Skipping push token upload. pushToken: \(pushToken), voipToken: \(voipToken)")
|
Logger.info("\(self.TAG) No reason to upload pushToken: \(pushToken), voipToken: \(voipToken)")
|
||||||
return Promise(value: ())
|
return Promise(value: ())
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.warn("\(self.TAG) Sending new tokens to account servers. pushToken: \(pushToken), voipToken: \(voipToken)")
|
Logger.warn("\(self.TAG) uploading tokens to account servers. pushToken: \(pushToken), voipToken: \(voipToken)")
|
||||||
|
|
||||||
return self.accountManager.updatePushTokens(pushToken:pushToken, voipToken:voipToken).then {
|
return self.accountManager.updatePushTokens(pushToken:pushToken, voipToken:voipToken).then {
|
||||||
return self.recordNewPushTokens(pushToken:pushToken, voipToken:voipToken)
|
Logger.info("\(self.TAG) successfully updated push tokens on server")
|
||||||
}.then {
|
return self.recordPushTokensLocally(pushToken:pushToken, voipToken:voipToken)
|
||||||
Logger.debug("\(self.TAG) Successfully ran syncPushTokensJob.")
|
|
||||||
}.catch { error in
|
|
||||||
Logger.error("\(self.TAG) Failed to run syncPushTokensJob with error: \(error).")
|
|
||||||
}
|
}
|
||||||
|
}.then {
|
||||||
|
Logger.info("\(self.TAG) in \(#function): succeeded")
|
||||||
|
}.catch { error in
|
||||||
|
Logger.error("\(self.TAG) in \(#function): Failed with error: \(error).")
|
||||||
}
|
}
|
||||||
|
|
||||||
runPromise.retainUntilComplete()
|
runPromise.retainUntilComplete()
|
||||||
|
@ -73,8 +77,8 @@ class SyncPushTokensJob: NSObject {
|
||||||
|
|
||||||
// MARK - objc wrappers, since objc can't use swift parameterized types
|
// MARK - objc wrappers, since objc can't use swift parameterized types
|
||||||
|
|
||||||
@objc class func run(pushManager: PushManager, accountManager: AccountManager, preferences: OWSPreferences) -> AnyPromise {
|
@objc class func run(accountManager: AccountManager, preferences: OWSPreferences) -> AnyPromise {
|
||||||
let promise: Promise<Void> = self.run(pushManager: pushManager, accountManager: accountManager, preferences: preferences)
|
let promise: Promise<Void> = self.run(accountManager: accountManager, preferences: preferences)
|
||||||
return AnyPromise(promise)
|
return AnyPromise(promise)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,21 +87,8 @@ class SyncPushTokensJob: NSObject {
|
||||||
return AnyPromise(promise)
|
return AnyPromise(promise)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK - private helpers
|
private func recordPushTokensLocally(pushToken: String, voipToken: String) -> Promise<Void> {
|
||||||
|
Logger.warn("\(TAG) Recording push tokens locally. pushToken: \(pushToken), voipToken: \(voipToken)")
|
||||||
private func requestPushTokens() -> Promise<(pushToken: String, voipToken: String)> {
|
|
||||||
return Promise { fulfill, reject in
|
|
||||||
self.pushManager.requestPushToken(
|
|
||||||
success: { (pushToken: String, voipToken: String) in
|
|
||||||
fulfill((pushToken:pushToken, voipToken:voipToken))
|
|
||||||
},
|
|
||||||
failure: reject
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private func recordNewPushTokens(pushToken: String, voipToken: String) -> Promise<Void> {
|
|
||||||
Logger.warn("\(TAG) Recording new push tokens. pushToken: \(pushToken), voipToken: \(voipToken)")
|
|
||||||
|
|
||||||
if (pushToken != self.preferences.getPushToken()) {
|
if (pushToken != self.preferences.getPushToken()) {
|
||||||
Logger.info("\(TAG) Recording new plain push token")
|
Logger.info("\(TAG) Recording new plain push token")
|
||||||
|
|
|
@ -241,8 +241,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
- (void)syncPushTokens
|
- (void)syncPushTokens
|
||||||
{
|
{
|
||||||
OWSSyncPushTokensJob *job =
|
OWSSyncPushTokensJob *job =
|
||||||
[[OWSSyncPushTokensJob alloc] initWithPushManager:[PushManager sharedManager]
|
[[OWSSyncPushTokensJob alloc] initWithAccountManager:[Environment getCurrent].accountManager
|
||||||
accountManager:[Environment getCurrent].accountManager
|
|
||||||
preferences:[Environment preferences]];
|
preferences:[Environment preferences]];
|
||||||
job.uploadOnlyIfStale = NO;
|
job.uploadOnlyIfStale = NO;
|
||||||
[job run]
|
[job run]
|
||||||
|
|
|
@ -9,9 +9,6 @@
|
||||||
|
|
||||||
@interface HomeViewController : OWSViewController
|
@interface HomeViewController : OWSViewController
|
||||||
|
|
||||||
// TODO: Remove this property.
|
|
||||||
@property (nonatomic) BOOL newlyRegisteredUser;
|
|
||||||
|
|
||||||
- (void)presentThread:(TSThread *)thread
|
- (void)presentThread:(TSThread *)thread
|
||||||
keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing
|
keyboardOnViewAppearing:(BOOL)keyboardOnViewAppearing
|
||||||
callOnViewAppearing:(BOOL)callOnViewAppearing;
|
callOnViewAppearing:(BOOL)callOnViewAppearing;
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
#import <PromiseKit/AnyPromise.h>
|
#import <PromiseKit/AnyPromise.h>
|
||||||
#import <SignalServiceKit/NSDate+OWS.h>
|
#import <SignalServiceKit/NSDate+OWS.h>
|
||||||
#import <SignalServiceKit/OWSBlockingManager.h>
|
#import <SignalServiceKit/OWSBlockingManager.h>
|
||||||
#import <SignalServiceKit/OWSDisappearingMessagesJob.h>
|
|
||||||
#import <SignalServiceKit/OWSMessageManager.h>
|
|
||||||
#import <SignalServiceKit/OWSMessageSender.h>
|
#import <SignalServiceKit/OWSMessageSender.h>
|
||||||
#import <SignalServiceKit/TSOutgoingMessage.h>
|
#import <SignalServiceKit/TSOutgoingMessage.h>
|
||||||
#import <SignalServiceKit/Threading.h>
|
#import <SignalServiceKit/Threading.h>
|
||||||
|
@ -490,13 +488,10 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
|
||||||
{
|
{
|
||||||
[super viewDidAppear:animated];
|
[super viewDidAppear:animated];
|
||||||
|
|
||||||
if (self.newlyRegisteredUser) {
|
if (!self.viewHasEverAppeared) {
|
||||||
[self markAllUpgradeExperiencesAsSeen];
|
self.viewHasEverAppeared = YES;
|
||||||
} else if (!self.viewHasEverAppeared) {
|
|
||||||
[self displayAnyUnseenUpgradeExperience];
|
[self displayAnyUnseenUpgradeExperience];
|
||||||
}
|
}
|
||||||
|
|
||||||
self.viewHasEverAppeared = YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - startup
|
#pragma mark - startup
|
||||||
|
|
|
@ -437,7 +437,6 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
|
||||||
- (void)showHomeView
|
- (void)showHomeView
|
||||||
{
|
{
|
||||||
HomeViewController *homeView = [HomeViewController new];
|
HomeViewController *homeView = [HomeViewController new];
|
||||||
homeView.newlyRegisteredUser = YES;
|
|
||||||
SignalsNavigationController *navigationController =
|
SignalsNavigationController *navigationController =
|
||||||
[[SignalsNavigationController alloc] initWithRootViewController:homeView];
|
[[SignalsNavigationController alloc] initWithRootViewController:homeView];
|
||||||
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
|
||||||
|
|
|
@ -27,8 +27,6 @@ NSString *const kTSStorageManager_lastKnownContactRecipientIds = @"lastKnownCont
|
||||||
|
|
||||||
@interface OWSContactsManager () <SystemContactsFetcherDelegate>
|
@interface OWSContactsManager () <SystemContactsFetcherDelegate>
|
||||||
|
|
||||||
@property (atomic) id addressBookReference;
|
|
||||||
@property (atomic) TOCFuture *futureAddressBook;
|
|
||||||
@property (nonatomic) BOOL isContactsUpdateInFlight;
|
@property (nonatomic) BOOL isContactsUpdateInFlight;
|
||||||
// This reflects the contents of the device phone book and includes
|
// This reflects the contents of the device phone book and includes
|
||||||
// contacts that do not correspond to any signal account.
|
// contacts that do not correspond to any signal account.
|
||||||
|
|
207
Signal/src/environment/PushRegistrationManager.swift
Normal file
207
Signal/src/environment/PushRegistrationManager.swift
Normal file
|
@ -0,0 +1,207 @@
|
||||||
|
//
|
||||||
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import PromiseKit
|
||||||
|
import PushKit
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Singleton used to integrate with push notification services - registration and routing received remote notifications.
|
||||||
|
*/
|
||||||
|
@objc class PushRegistrationManager: NSObject, PKPushRegistryDelegate {
|
||||||
|
|
||||||
|
let TAG = "[PushRegistrationManager]"
|
||||||
|
|
||||||
|
// MARK - Dependencies
|
||||||
|
private var pushManager: PushManager {
|
||||||
|
return PushManager.shared()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK - Singleton class
|
||||||
|
|
||||||
|
@objc(sharedManager)
|
||||||
|
static let shared = PushRegistrationManager()
|
||||||
|
private override init() {
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum PushRegistrationManagerError: Error {
|
||||||
|
case assertionError(description: String)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var voipRegistry: PKPushRegistry?
|
||||||
|
private var fulfillVanillaTokenPromise: ((Data) -> Void)?
|
||||||
|
private var rejectVanillaTokenPromise: ((Error) -> Void)?
|
||||||
|
private var fulfillVoipTokenPromise: ((Data) -> Void)?
|
||||||
|
private var fulfillRegisterUserNotificationSettingsPromise: (() -> Void)?
|
||||||
|
|
||||||
|
// MARK: Public interface
|
||||||
|
|
||||||
|
public func requestPushTokens() -> Promise<(pushToken: String, voipToken: String)> {
|
||||||
|
Logger.info("\(self.TAG) in \(#function)")
|
||||||
|
|
||||||
|
return self.registerUserNotificationSettings().then {
|
||||||
|
guard !Platform.isSimulator else {
|
||||||
|
Logger.warn("\(self.TAG) Using fake push tokens for simulator")
|
||||||
|
return Promise(value: (pushToken: "fakePushToken", voipToken: "fakeVoipToken"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.registerForVanillaPushToken().then { vanillaPushToken in
|
||||||
|
self.registerForVoipPushToken().then { voipPushToken in
|
||||||
|
(pushToken: vanillaPushToken, voipToken: voipPushToken)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notification registration is confirmed via AppDelegate
|
||||||
|
// Before this occurs, it is not safe to assume push token requests will be acknowledged.
|
||||||
|
//
|
||||||
|
// e.g. in the case that Background Fetch is disabled, token requests will be ignored until
|
||||||
|
// we register user notification settings.
|
||||||
|
@objc
|
||||||
|
public func didRegisterUserNotificationSettings() {
|
||||||
|
guard let fulfillRegisterUserNotificationSettingsPromise = self.fulfillRegisterUserNotificationSettingsPromise else {
|
||||||
|
owsFail("\(TAG) promise completion in \(#function) unexpectedly nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fulfillRegisterUserNotificationSettingsPromise()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Vanilla push token
|
||||||
|
|
||||||
|
// Vanilla push token is obtained from the system via AppDelegate
|
||||||
|
@objc
|
||||||
|
public func didReceiveVanillaPushToken(_ tokenData: Data) {
|
||||||
|
guard let fulfillVanillaTokenPromise = self.fulfillVanillaTokenPromise else {
|
||||||
|
owsFail("\(TAG) promise completion in \(#function) unexpectedly nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fulfillVanillaTokenPromise(tokenData)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vanilla push token is obtained from the system via AppDelegate
|
||||||
|
@objc
|
||||||
|
public func didFailToReceiveVanillaPushToken(error: Error) {
|
||||||
|
guard let rejectVanillaTokenPromise = self.rejectVanillaTokenPromise else {
|
||||||
|
owsFail("\(TAG) promise completion in \(#function) unexpectedly nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rejectVanillaTokenPromise(error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: PKPushRegistryDelegate - voIP Push Token
|
||||||
|
|
||||||
|
public func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
|
||||||
|
Logger.info("\(self.TAG) in \(#function)")
|
||||||
|
assert(type == .voIP)
|
||||||
|
self.pushManager.application(UIApplication.shared, didReceiveRemoteNotification: payload.dictionaryPayload)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, forType type: PKPushType) {
|
||||||
|
Logger.info("\(self.TAG) in \(#function)")
|
||||||
|
assert(type == .voIP)
|
||||||
|
assert(credentials.type == .voIP)
|
||||||
|
guard let fulfillVoipTokenPromise = self.fulfillVoipTokenPromise else {
|
||||||
|
owsFail("\(TAG) fulfillVoipTokenPromise was unexpectedly nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fulfillVoipTokenPromise(credentials.token)
|
||||||
|
}
|
||||||
|
|
||||||
|
public func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenForType type: PKPushType) {
|
||||||
|
// It's not clear when this would happen. We've never previously handled it, but we should at
|
||||||
|
// least start learning if it happens.
|
||||||
|
owsFail("\(TAG) in \(#function)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: helpers
|
||||||
|
|
||||||
|
// User notification settings must be registered *before* AppDelegate will
|
||||||
|
// return any requested push tokens. We don't consider the notifications settings registration
|
||||||
|
// *complete* until AppDelegate#didRegisterUserNotificationSettings is called.
|
||||||
|
private func registerUserNotificationSettings() -> Promise<Void> {
|
||||||
|
AssertIsOnMainThread()
|
||||||
|
|
||||||
|
guard fulfillRegisterUserNotificationSettingsPromise == nil else {
|
||||||
|
Logger.info("\(TAG) already registered user notification settings")
|
||||||
|
return Promise(value: ())
|
||||||
|
}
|
||||||
|
|
||||||
|
let (promise, fulfill, _) = Promise<Void>.pending()
|
||||||
|
self.fulfillRegisterUserNotificationSettingsPromise = fulfill
|
||||||
|
|
||||||
|
Logger.info("\(TAG) registering user notification settings")
|
||||||
|
|
||||||
|
UIApplication.shared.registerUserNotificationSettings(self.pushManager.userNotificationSettings)
|
||||||
|
|
||||||
|
return promise
|
||||||
|
}
|
||||||
|
|
||||||
|
private func registerForVanillaPushToken() -> Promise<String> {
|
||||||
|
Logger.info("\(self.TAG) in \(#function)")
|
||||||
|
AssertIsOnMainThread()
|
||||||
|
|
||||||
|
let (promise, fulfill, reject) = Promise<Data>.pending()
|
||||||
|
self.fulfillVanillaTokenPromise = fulfill
|
||||||
|
self.rejectVanillaTokenPromise = reject
|
||||||
|
UIApplication.shared.registerForRemoteNotifications()
|
||||||
|
|
||||||
|
return promise.then { (pushTokenData: Data) -> String in
|
||||||
|
Logger.info("\(self.TAG) successfully registered for vanilla push notifications")
|
||||||
|
return pushTokenData.hexEncodedString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func registerForVoipPushToken() -> Promise<String> {
|
||||||
|
AssertIsOnMainThread()
|
||||||
|
Logger.info("\(self.TAG) in \(#function)")
|
||||||
|
|
||||||
|
// Voip token not yet registered, assign promise.
|
||||||
|
let (promise, fulfill, reject) = Promise<Data>.pending()
|
||||||
|
self.fulfillVoipTokenPromise = fulfill
|
||||||
|
|
||||||
|
if self.voipRegistry == nil {
|
||||||
|
// We don't create the voip registry in init, because it immediately requests the voip token,
|
||||||
|
// potentially before we're ready to handle it.
|
||||||
|
let voipRegistry = PKPushRegistry(queue: nil)
|
||||||
|
self.voipRegistry = voipRegistry
|
||||||
|
voipRegistry.desiredPushTypes = [.voIP]
|
||||||
|
voipRegistry.delegate = self
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let voipRegistry = self.voipRegistry else {
|
||||||
|
owsFail("\(TAG) failed to initialize voipRegistry in \(#function)")
|
||||||
|
reject(PushRegistrationManagerError.assertionError(description: "\(TAG) failed to initialize voipRegistry in \(#function)"))
|
||||||
|
return promise.then { _ in
|
||||||
|
// coerce expected type of returned promise - we don't really care about the value, since this promise has been rejected.
|
||||||
|
// in practice this shouldn't happen
|
||||||
|
String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we've already completed registering for a voip token, resolve it immediately,
|
||||||
|
// rather than waiting for the delegate method to be called.
|
||||||
|
if let voipTokenData = voipRegistry.pushToken(forType: .voIP) {
|
||||||
|
Logger.info("\(self.TAG) using pre-registered voIP token")
|
||||||
|
fulfill(voipTokenData)
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise.then { (voipTokenData: Data) -> String in
|
||||||
|
Logger.info("\(self.TAG) successfully registered for voip push notifications")
|
||||||
|
return voipTokenData.hexEncodedString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We transmit pushToken data as hex encoded string to the server
|
||||||
|
fileprivate extension Data {
|
||||||
|
func hexEncodedString() -> String {
|
||||||
|
return map { String(format: "%02hhx", $0) }.joined()
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,6 @@
|
||||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#import <CollapsingFutures.h>
|
|
||||||
#import <PushKit/PushKit.h>
|
|
||||||
#import <UIKit/UIApplication.h>
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@class UILocalNotification;
|
@class UILocalNotification;
|
||||||
|
@ -37,38 +33,19 @@ typedef void (^failedPushRegistrationBlock)(NSError *error);
|
||||||
typedef void (^pushTokensSuccessBlock)(NSString *pushToken, NSString *voipToken);
|
typedef void (^pushTokensSuccessBlock)(NSString *pushToken, NSString *voipToken);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Push Manager is responsible for registering the device for Signal push notifications.
|
* The Push Manager is responsible for handling received push notifications.
|
||||||
*/
|
*/
|
||||||
|
@interface PushManager : NSObject
|
||||||
@interface PushManager : NSObject <PKPushRegistryDelegate>
|
|
||||||
|
|
||||||
- (instancetype)init NS_UNAVAILABLE;
|
- (instancetype)init NS_UNAVAILABLE;
|
||||||
|
|
||||||
+ (PushManager *)sharedManager;
|
+ (PushManager *)sharedManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Push Notification Token of this device
|
* Settings required for the notification categories we use.
|
||||||
*
|
|
||||||
* @param success Completion block that is passed the token as a parameter
|
|
||||||
* @param failure Failure block, executed when failed to get push token
|
|
||||||
*/
|
*/
|
||||||
- (void)requestPushTokenWithSuccess:(pushTokensSuccessBlock)success failure:(void (^)(NSError *))failure;
|
@property (nonatomic, readonly) UIUserNotificationSettings *userNotificationSettings;
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers for Users Notifications. By doing this on launch, we are sure that the correct categories of user
|
|
||||||
* notifications is registered.
|
|
||||||
*/
|
|
||||||
- (void)validateUserNotificationSettings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The pushNotification and userNotificationFutureSource are accessed by the App Delegate after requested permissions.
|
|
||||||
*/
|
|
||||||
@property (nullable, atomic, readwrite, strong) TOCFutureSource *pushNotificationFutureSource;
|
|
||||||
@property (nullable, atomic, readwrite, strong) TOCFutureSource *userNotificationFutureSource;
|
|
||||||
@property (nullable, atomic, readwrite, strong) TOCFutureSource *pushKitNotificationFutureSource;
|
|
||||||
|
|
||||||
- (TOCFuture *)registerPushKitNotificationFuture;
|
|
||||||
- (BOOL)supportsVOIPPush;
|
|
||||||
// If checkForCancel is set, the notification will be delayed for
|
// If checkForCancel is set, the notification will be delayed for
|
||||||
// a moment. If a relevant cancel notification is received in that window,
|
// a moment. If a relevant cancel notification is received in that window,
|
||||||
// the notification will not be displayed.
|
// the notification will not be displayed.
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
#import "PushManager.h"
|
#import "PushManager.h"
|
||||||
#import "AppDelegate.h"
|
#import "AppDelegate.h"
|
||||||
#import "NSData+ows_StripToken.h"
|
|
||||||
#import "OWSContactsManager.h"
|
#import "OWSContactsManager.h"
|
||||||
#import "Signal-Swift.h"
|
#import "Signal-Swift.h"
|
||||||
#import "ThreadUtil.h"
|
#import "ThreadUtil.h"
|
||||||
|
@ -30,7 +29,6 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
|
||||||
|
|
||||||
@interface PushManager ()
|
@interface PushManager ()
|
||||||
|
|
||||||
@property (nonatomic) TOCFutureSource *registerWithServerFutureSource;
|
|
||||||
@property (nonatomic) NSMutableArray *currentNotifications;
|
@property (nonatomic) NSMutableArray *currentNotifications;
|
||||||
@property (nonatomic) UIBackgroundTaskIdentifier callBackgroundTask;
|
@property (nonatomic) UIBackgroundTaskIdentifier callBackgroundTask;
|
||||||
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
@property (nonatomic, readonly) OWSMessageSender *messageSender;
|
||||||
|
@ -72,6 +70,7 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
|
||||||
_messageSender = messageSender;
|
_messageSender = messageSender;
|
||||||
_messageFetcherJob = messageFetcherJob;
|
_messageFetcherJob = messageFetcherJob;
|
||||||
_callBackgroundTask = UIBackgroundTaskInvalid;
|
_callBackgroundTask = UIBackgroundTaskInvalid;
|
||||||
|
// TODO: consolidate notification tracking with NotificationsManager, which also maintains a list of notifications.
|
||||||
_currentNotifications = [NSMutableArray array];
|
_currentNotifications = [NSMutableArray array];
|
||||||
|
|
||||||
OWSSingletonAssert();
|
OWSSingletonAssert();
|
||||||
|
@ -98,8 +97,9 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
|
||||||
|
|
||||||
#pragma mark Manage Incoming Push
|
#pragma mark Manage Incoming Push
|
||||||
|
|
||||||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
|
||||||
DDLogInfo(@"received: %s", __PRETTY_FUNCTION__);
|
{
|
||||||
|
DDLogInfo(@"%@ received remote notification", self.tag);
|
||||||
|
|
||||||
[self.messageFetcherJob runAsync];
|
[self.messageFetcherJob runAsync];
|
||||||
}
|
}
|
||||||
|
@ -113,19 +113,23 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
|
||||||
* "content-available:1" pushes if there is no "voip" token registered
|
* "content-available:1" pushes if there is no "voip" token registered
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
- (void)application:(UIApplication *)application
|
- (void)application:(UIApplication *)application
|
||||||
didReceiveRemoteNotification:(NSDictionary *)userInfo
|
didReceiveRemoteNotification:(NSDictionary *)userInfo
|
||||||
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
|
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
|
||||||
DDLogInfo(@"received: %s", __PRETTY_FUNCTION__);
|
{
|
||||||
|
DDLogInfo(@"%@ received content-available push", self.tag);
|
||||||
|
|
||||||
|
// If we want to re-introduce silent pushes we can remove this assert.
|
||||||
|
OWSFail(@"Unexpected content-available push.");
|
||||||
|
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 20 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
|
||||||
completionHandler(UIBackgroundFetchResultNewData);
|
completionHandler(UIBackgroundFetchResultNewData);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
|
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
|
||||||
DDLogInfo(@"received: %s", __PRETTY_FUNCTION__);
|
{
|
||||||
|
DDLogInfo(@"%@ launched from local notification", self.tag);
|
||||||
|
|
||||||
NSString *_Nullable threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
|
NSString *_Nullable threadId = notification.userInfo[Signal_Thread_UserInfo_Key];
|
||||||
|
|
||||||
|
@ -139,8 +143,9 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
|
||||||
- (void)application:(UIApplication *)application
|
- (void)application:(UIApplication *)application
|
||||||
handleActionWithIdentifier:(NSString *)identifier
|
handleActionWithIdentifier:(NSString *)identifier
|
||||||
forLocalNotification:(UILocalNotification *)notification
|
forLocalNotification:(UILocalNotification *)notification
|
||||||
completionHandler:(void (^)())completionHandler {
|
completionHandler:(void (^)())completionHandler
|
||||||
DDLogInfo(@"received: %s", __PRETTY_FUNCTION__);
|
{
|
||||||
|
DDLogInfo(@"%@ in %s", self.tag, __FUNCTION__);
|
||||||
|
|
||||||
[self application:application
|
[self application:application
|
||||||
handleActionWithIdentifier:identifier
|
handleActionWithIdentifier:identifier
|
||||||
|
@ -264,82 +269,6 @@ NSString *const Signal_Message_MarkAsRead_Identifier = @"Signal_Message_MarkAsRe
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark PushKit
|
|
||||||
|
|
||||||
- (void)pushRegistry:(PKPushRegistry *)registry
|
|
||||||
didUpdatePushCredentials:(PKPushCredentials *)credentials
|
|
||||||
forType:(NSString *)type {
|
|
||||||
[[PushManager sharedManager].pushKitNotificationFutureSource trySetResult:[credentials.token ows_tripToken]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)pushRegistry:(PKPushRegistry *)registry
|
|
||||||
didReceiveIncomingPushWithPayload:(PKPushPayload *)payload
|
|
||||||
forType:(NSString *)type {
|
|
||||||
|
|
||||||
DDLogInfo(@"received: %s", __PRETTY_FUNCTION__);
|
|
||||||
|
|
||||||
[self application:[UIApplication sharedApplication] didReceiveRemoteNotification:payload.dictionaryPayload];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (TOCFuture *)registerPushKitNotificationFuture {
|
|
||||||
if ([self supportsVOIPPush]) {
|
|
||||||
self.pushKitNotificationFutureSource = [TOCFutureSource new];
|
|
||||||
PKPushRegistry *voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
|
|
||||||
voipRegistry.delegate = self;
|
|
||||||
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
|
|
||||||
return self.pushKitNotificationFutureSource.future;
|
|
||||||
} else {
|
|
||||||
TOCFutureSource *futureSource = [TOCFutureSource new];
|
|
||||||
[futureSource trySetResult:nil];
|
|
||||||
return futureSource.future;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL)supportsVOIPPush {
|
|
||||||
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(8, 2)) {
|
|
||||||
return YES;
|
|
||||||
} else {
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark Register device for Push Notification locally
|
|
||||||
|
|
||||||
- (TOCFuture *)registerPushNotificationFuture {
|
|
||||||
self.pushNotificationFutureSource = [TOCFutureSource new];
|
|
||||||
[UIApplication.sharedApplication registerForRemoteNotifications];
|
|
||||||
return self.pushNotificationFutureSource.future;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)requestPushTokenWithSuccess:(pushTokensSuccessBlock)success failure:(failedPushRegistrationBlock)failure {
|
|
||||||
AssertIsOnMainThread();
|
|
||||||
|
|
||||||
if (!self.wantRemoteNotifications) {
|
|
||||||
DDLogWarn(@"%@ Using fake push tokens", self.tag);
|
|
||||||
success(@"fakePushToken", @"fakeVoipToken");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TOCFuture *requestPushTokenFuture = [self registerPushNotificationFuture];
|
|
||||||
|
|
||||||
[requestPushTokenFuture thenDo:^(NSData *pushTokenData) {
|
|
||||||
NSString *pushToken = [pushTokenData ows_tripToken];
|
|
||||||
TOCFuture *pushKit = [self registerPushKitNotificationFuture];
|
|
||||||
|
|
||||||
[pushKit thenDo:^(NSString *voipToken) {
|
|
||||||
success(pushToken, voipToken);
|
|
||||||
}];
|
|
||||||
|
|
||||||
[pushKit catchDo:^(NSError *error) {
|
|
||||||
failure(error);
|
|
||||||
}];
|
|
||||||
}];
|
|
||||||
|
|
||||||
[requestPushTokenFuture catchDo:^(NSError *error) {
|
|
||||||
failure(error);
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (UIUserNotificationCategory *)fullNewMessageNotificationCategory {
|
- (UIUserNotificationCategory *)fullNewMessageNotificationCategory {
|
||||||
UIMutableUserNotificationAction *action_markRead = [self markAsReadAction];
|
UIMutableUserNotificationAction *action_markRead = [self markAsReadAction];
|
||||||
|
|
||||||
|
@ -464,20 +393,13 @@ NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManager
|
||||||
|
|
||||||
#pragma mark Util
|
#pragma mark Util
|
||||||
|
|
||||||
- (BOOL)wantRemoteNotifications {
|
|
||||||
#if TARGET_IPHONE_SIMULATOR
|
|
||||||
return NO;
|
|
||||||
#else
|
|
||||||
return YES;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
- (int)allNotificationTypes {
|
- (int)allNotificationTypes {
|
||||||
return UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge;
|
return UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)validateUserNotificationSettings
|
- (UIUserNotificationSettings *)userNotificationSettings
|
||||||
{
|
{
|
||||||
|
DDLogDebug(@"%@ registering user notification settings", self.tag);
|
||||||
UIUserNotificationSettings *settings = [UIUserNotificationSettings
|
UIUserNotificationSettings *settings = [UIUserNotificationSettings
|
||||||
settingsForTypes:(UIUserNotificationType)[self allNotificationTypes]
|
settingsForTypes:(UIUserNotificationType)[self allNotificationTypes]
|
||||||
categories:[NSSet setWithObjects:[self fullNewMessageNotificationCategory],
|
categories:[NSSet setWithObjects:[self fullNewMessageNotificationCategory],
|
||||||
|
@ -487,7 +409,7 @@ NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManager
|
||||||
[self signalMissedCallWithNoLongerVerifiedIdentityChangeCategory],
|
[self signalMissedCallWithNoLongerVerifiedIdentityChangeCategory],
|
||||||
nil]];
|
nil]];
|
||||||
|
|
||||||
[UIApplication.sharedApplication registerUserNotificationSettings:settings];
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)applicationIsActive {
|
- (BOOL)applicationIsActive {
|
||||||
|
@ -500,6 +422,7 @@ NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManager
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: consolidate notification tracking with NotificationsManager, which also maintains a list of notifications.
|
||||||
- (void)presentNotification:(UILocalNotification *)notification checkForCancel:(BOOL)checkForCancel
|
- (void)presentNotification:(UILocalNotification *)notification checkForCancel:(BOOL)checkForCancel
|
||||||
{
|
{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
@ -517,6 +440,7 @@ NSString *const PushManagerUserInfoKeysCallBackSignalRecipientId = @"PushManager
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: consolidate notification tracking with NotificationsManager, which also maintains a list of notifications.
|
||||||
- (void)cancelNotificationsWithThreadId:(NSString *)threadId
|
- (void)cancelNotificationsWithThreadId:(NSString *)threadId
|
||||||
{
|
{
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
//
|
|
||||||
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@interface NSData (ows_StripToken)
|
|
||||||
|
|
||||||
- (NSString *)ows_tripToken;
|
|
||||||
|
|
||||||
@end
|
|
|
@ -1,20 +0,0 @@
|
||||||
//
|
|
||||||
// NSData+ows_StripToken.m
|
|
||||||
// Signal
|
|
||||||
//
|
|
||||||
// Created by Frederic Jacobs on 14/04/15.
|
|
||||||
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import "NSData+ows_StripToken.h"
|
|
||||||
|
|
||||||
@implementation NSData (ows_StripToken)
|
|
||||||
|
|
||||||
- (NSString *)ows_tripToken {
|
|
||||||
return [[[NSString stringWithFormat:@"%@", self]
|
|
||||||
stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
|
|
||||||
stringByReplacingOccurrencesOfString:@" "
|
|
||||||
withString:@""];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
|
@ -65,6 +65,12 @@ extern NSString *const kNSNotificationName_LocalNumberDidChange;
|
||||||
success:(void (^)())successBlock
|
success:(void (^)())successBlock
|
||||||
failure:(void (^)(NSError *error))failureBlock;
|
failure:(void (^)(NSError *error))failureBlock;
|
||||||
|
|
||||||
|
// Called once registration is complete - meaning the following have succeeded:
|
||||||
|
// - obtained signal server credentials
|
||||||
|
// - uploaded pre-keys
|
||||||
|
// - uploaded push tokens
|
||||||
|
- (void)didRegister;
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -290,11 +290,6 @@ NSString *const TSAccountManager_LocalRegistrationIdKey = @"TSStorageLocalRegist
|
||||||
forNumber:phoneNumber
|
forNumber:phoneNumber
|
||||||
signalingKey:signalingKey
|
signalingKey:signalingKey
|
||||||
authKey:authToken];
|
authKey:authToken];
|
||||||
void (^completedRegistrationBlock)() = ^{
|
|
||||||
[self didRegister];
|
|
||||||
[TSSocketManager requestSocketOpen];
|
|
||||||
successBlock();
|
|
||||||
};
|
|
||||||
|
|
||||||
[self.networkManager makeRequest:request
|
[self.networkManager makeRequest:request
|
||||||
success:^(NSURLSessionDataTask *task, id responseObject) {
|
success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||||
|
@ -304,9 +299,10 @@ NSString *const TSAccountManager_LocalRegistrationIdKey = @"TSStorageLocalRegist
|
||||||
switch (statuscode) {
|
switch (statuscode) {
|
||||||
case 200:
|
case 200:
|
||||||
case 204: {
|
case 204: {
|
||||||
|
DDLogInfo(@"%@ Verification code accepted.", self.tag);
|
||||||
[TSStorageManager storeServerToken:authToken signalingKey:signalingKey];
|
[TSStorageManager storeServerToken:authToken signalingKey:signalingKey];
|
||||||
[TSPreKeyManager registerPreKeysWithMode:RefreshPreKeysMode_SignedAndOneTime
|
[TSPreKeyManager registerPreKeysWithMode:RefreshPreKeysMode_SignedAndOneTime
|
||||||
success:completedRegistrationBlock
|
success:successBlock
|
||||||
failure:failureBlock];
|
failure:failureBlock];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,7 +164,7 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
|
||||||
self.state = SocketManagerStateOpen;
|
self.state = SocketManagerStateOpen;
|
||||||
return;
|
return;
|
||||||
case SR_CONNECTING:
|
case SR_CONNECTING:
|
||||||
DDLogVerbose(@"WebSocket is already connecting");
|
DDLogVerbose(@"%@ WebSocket is already connecting", self.tag);
|
||||||
self.state = SocketManagerStateConnecting;
|
self.state = SocketManagerStateConnecting;
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
|
@ -172,7 +172,7 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DDLogWarn(@"Creating new websocket");
|
DDLogWarn(@"%@ Creating new websocket", self.tag);
|
||||||
|
|
||||||
// If socket is not already open or connecting, connect now.
|
// If socket is not already open or connecting, connect now.
|
||||||
//
|
//
|
||||||
|
@ -373,7 +373,7 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
|
||||||
- (void)processWebSocketRequestMessage:(WebSocketRequestMessage *)message {
|
- (void)processWebSocketRequestMessage:(WebSocketRequestMessage *)message {
|
||||||
OWSAssert([NSThread isMainThread]);
|
OWSAssert([NSThread isMainThread]);
|
||||||
|
|
||||||
DDLogInfo(@"Got message with verb: %@ and path: %@", message.verb, message.path);
|
DDLogInfo(@"%@ Got message with verb: %@ and path: %@", self.tag, message.verb, message.path);
|
||||||
|
|
||||||
// If we receive a message over the socket while the app is in the background,
|
// If we receive a message over the socket while the app is in the background,
|
||||||
// prolong how long the socket stays open.
|
// prolong how long the socket stays open.
|
||||||
|
@ -385,7 +385,7 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
|
||||||
[Cryptography decryptAppleMessagePayload:message.body withSignalingKey:TSStorageManager.signalingKey];
|
[Cryptography decryptAppleMessagePayload:message.body withSignalingKey:TSStorageManager.signalingKey];
|
||||||
|
|
||||||
if (!decryptedPayload) {
|
if (!decryptedPayload) {
|
||||||
DDLogWarn(@"Failed to decrypt incoming payload or bad HMAC");
|
DDLogWarn(@"%@ Failed to decrypt incoming payload or bad HMAC", self.tag);
|
||||||
[self sendWebSocketMessageAcknowledgement:message];
|
[self sendWebSocketMessageAcknowledgement:message];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -396,7 +396,7 @@ NSString *const kNSNotification_SocketManagerStateDidChange = @"kNSNotification_
|
||||||
[self sendWebSocketMessageAcknowledgement:message];
|
[self sendWebSocketMessageAcknowledgement:message];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
DDLogWarn(@"Unsupported WebSocket Request");
|
DDLogWarn(@"%@ Unsupported WebSocket Request", self.tag);
|
||||||
|
|
||||||
[self sendWebSocketMessageAcknowledgement:message];
|
[self sendWebSocketMessageAcknowledgement:message];
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,15 +55,15 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault
|
||||||
forKey:kNSUserDefaults_LastAppVersion];
|
forKey:kNSUserDefaults_LastAppVersion];
|
||||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
|
|
||||||
DDLogInfo(@"firstAppVersion: %@", self.firstAppVersion);
|
DDLogInfo(@"%@ firstAppVersion: %@", self.tag, self.firstAppVersion);
|
||||||
DDLogInfo(@"lastAppVersion: %@", self.lastAppVersion);
|
DDLogInfo(@"%@ lastAppVersion: %@", self.tag, self.lastAppVersion);
|
||||||
DDLogInfo(@"currentAppVersion: %@", self.currentAppVersion);
|
DDLogInfo(@"%@ currentAppVersion: %@", self.tag, self.currentAppVersion);
|
||||||
DDLogInfo(@"lastCompletedLaunchAppVersion: %@", self.lastCompletedLaunchAppVersion);
|
DDLogInfo(@"%@ lastCompletedLaunchAppVersion: %@", self.tag, self.lastCompletedLaunchAppVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)appLaunchDidComplete
|
- (void)appLaunchDidComplete
|
||||||
{
|
{
|
||||||
DDLogInfo(@"appLaunchDidComplete");
|
DDLogInfo(@"%@ appLaunchDidComplete", self.tag);
|
||||||
|
|
||||||
self.lastCompletedLaunchAppVersion = self.currentAppVersion;
|
self.lastCompletedLaunchAppVersion = self.currentAppVersion;
|
||||||
|
|
||||||
|
@ -78,4 +78,16 @@ NSString *const kNSUserDefaults_LastCompletedLaunchAppVersion = @"kNSUserDefault
|
||||||
return self.firstAppVersion != nil;
|
return self.firstAppVersion != nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - Logging
|
||||||
|
|
||||||
|
+ (NSString *)tag
|
||||||
|
{
|
||||||
|
return [NSString stringWithFormat:@"[%@]", self.class];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)tag
|
||||||
|
{
|
||||||
|
return self.class.tag;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in a new issue