diff --git a/Signal/src/AppDelegate.h b/Signal/src/AppDelegate.h index 915a72dc9..936ae0b21 100644 --- a/Signal/src/AppDelegate.h +++ b/Signal/src/AppDelegate.h @@ -10,5 +10,6 @@ extern NSString *const AppDelegateStoryboardMain; @interface AppDelegate : UIResponder +@property (atomic) BOOL isEnvironmentSetup; @end diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index d4e1e9383..da84a3a81 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -493,6 +493,11 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // Clean up any messages that expired since last launch immediately // and continue cleaning in the background. [[OWSDisappearingMessagesJob sharedJob] startIfNecessary]; + + // TODO remove this once we're sure our app boot process is coherent. + // Currently this happens *before* db registration is complete when + // launching the app directly, but *after* db registration is complete when + // the app is launched in the background, e.g. from a voip notification. [[OWSProfileManager sharedManager] ensureLocalProfileCached]; // Mark all "attempting out" messages as "unsent", i.e. any messages that were not successfully @@ -752,6 +757,11 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; } - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { + if (!self.isEnvironmentSetup) { + OWSFail(@"%@ ignoring %s because environment is not yet set up.", self.tag, __PRETTY_FUNCTION__); + return; + } + [AppStoreRating preventPromptAtNextTest]; [[PushManager sharedManager] application:application didReceiveLocalNotification:notification]; } @@ -759,7 +769,13 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification - completionHandler:(void (^)())completionHandler { + completionHandler:(void (^)())completionHandler +{ + if (!self.isEnvironmentSetup) { + OWSFail(@"%@ ignoring %s because environment is not yet set up.", self.tag, __PRETTY_FUNCTION__); + return; + } + [[PushManager sharedManager] application:application handleActionWithIdentifier:identifier forLocalNotification:notification @@ -770,7 +786,13 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo - completionHandler:(void (^)())completionHandler { + completionHandler:(void (^)())completionHandler +{ + if (!self.isEnvironmentSetup) { + OWSFail(@"%@ ignoring %s because environment is not yet set up.", self.tag, __PRETTY_FUNCTION__); + return; + } + [[PushManager sharedManager] application:application handleActionWithIdentifier:identifier forLocalNotification:notification @@ -811,6 +833,10 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; // If there were any messages in our local queue which we hadn't yet processed. [[OWSMessageReceiver sharedInstance] handleAnyUnprocessedEnvelopesAsync]; + [[OWSProfileManager sharedManager] ensureLocalProfileCached]; + + self.isEnvironmentSetup = YES; + [OWSProfileManager.sharedManager fetchLocalUsersProfile]; }