From 9f2a2d1ee668532de7ec3d40aeb5b567c1952e0e Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 19 Jun 2017 14:53:47 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20show=20=E2=80=9Cexport=20with?= =?UTF-8?q?=20Signal=E2=80=9D=20UI=20until=20async=20database=20view=20reg?= =?UTF-8?q?istration=20is=20complete.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Signal/src/AppDelegate.m | 51 +++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 7d1596299..aabe4263b 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -416,20 +416,14 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; } DDLogInfo(@"Application opened with URL: %@", url); - [[TSAccountManager sharedInstance] - ifRegistered:YES - runAsync:^{ - dispatch_async(dispatch_get_main_queue(), ^{ - SendExternalFileViewController *viewController = [SendExternalFileViewController new]; - viewController.attachment = attachment; - UINavigationController *navigationController = - [[UINavigationController alloc] initWithRootViewController:viewController]; - [[[Environment getCurrent] signalsViewController] - presentTopLevelModalViewController:navigationController - animateDismissal:NO - animatePresentation:YES]; - }); - }]; + [[TSAccountManager sharedInstance] ifRegistered:YES + runAsync:^{ + dispatch_async(dispatch_get_main_queue(), ^{ + // Wait up to N seconds for database view registrations to + // complete. + [self showImportUIForAttachment:attachment remainingRetries:5]; + }); + }]; return YES; } else { @@ -438,6 +432,35 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; return NO; } +- (void)showImportUIForAttachment:(SignalAttachment *)attachment remainingRetries:(int)remainingRetries +{ + OWSAssert([NSThread isMainThread]); + OWSAssert(attachment); + OWSAssert(remainingRetries > 0); + + if ([TSDatabaseView hasPendingViewRegistrations]) { + if (remainingRetries < 1) { + DDLogInfo(@"Ignoring 'Import with Signal...' due to pending view registrations."); + } else { + DDLogInfo(@"Delaying 'Import with Signal...' due to pending view registrations."); + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ + if (![TSDatabaseView hasPendingViewRegistrations]) { + [self showImportUIForAttachment:attachment remainingRetries:remainingRetries - 1]; + } + }); + } + return; + } + + SendExternalFileViewController *viewController = [SendExternalFileViewController new]; + viewController.attachment = attachment; + UINavigationController *navigationController = + [[UINavigationController alloc] initWithRootViewController:viewController]; + [[[Environment getCurrent] signalsViewController] presentTopLevelModalViewController:navigationController + animateDismissal:NO + animatePresentation:YES]; +} + - (void)applicationDidBecomeActive:(UIApplication *)application { DDLogWarn(@"%@ applicationDidBecomeActive.", self.tag);