diff --git a/Signal/src/ViewControllers/ExperienceUpgradesPageViewController.swift b/Signal/src/ViewControllers/ExperienceUpgradesPageViewController.swift index 8d8b2bc634..184c159f70 100644 --- a/Signal/src/ViewControllers/ExperienceUpgradesPageViewController.swift +++ b/Signal/src/ViewControllers/ExperienceUpgradesPageViewController.swift @@ -44,8 +44,8 @@ private class IntroducingCustomNotificationAudioExperienceUpgradeViewController: let button = addButton(title: buttonTitle) { _ in // dismiss the modally presented view controller, then proceed. self.experienceUpgradesPageViewController.dismiss(animated: true) { - guard let fromViewController = UIApplication.shared.frontmostViewController as? HomeViewController else { - owsFail("unexpected frontmostViewController: \(String(describing: UIApplication.shared.frontmostViewController))") + guard let fromViewController = UIApplication.shared.frontmostViewController else { + owsFail("frontmostViewController was unexectedly nil") return } @@ -490,12 +490,15 @@ class ExperienceUpgradesPageViewController: OWSViewController, UIPageViewControl let pageViewController: UIPageViewController + let editingDBConnection: YapDatabaseConnection + // MARK: - Initializers required init(experienceUpgrades: [ExperienceUpgrade]) { self.experienceUpgrades = experienceUpgrades setPageControlAppearance() + self.editingDBConnection = TSStorageManager.shared().newDatabaseConnection() self.pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil) super.init(nibName: nil, bundle: nil) self.pageViewController.dataSource = self @@ -505,12 +508,7 @@ class ExperienceUpgradesPageViewController: OWSViewController, UIPageViewControl @available(*, unavailable, message:"unavailable, use initWithExperienceUpgrade instead") required init?(coder aDecoder: NSCoder) { - assert(false) - // This should never happen, but so as not to explode we give some bogus data - self.experienceUpgrades = [ExperienceUpgrade()] - self.pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil) - super.init(coder: aDecoder) - self.pageViewController.dataSource = self + fatalError("unimplemented") } // MARK: - View lifecycle @@ -679,6 +677,16 @@ class ExperienceUpgradesPageViewController: OWSViewController, UIPageViewControl allViewControllers.append(viewController) } + override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) { + // Blocking write before dismiss, to be sure they're marked as complete + // before HomeView.didAppear is re-fired. + self.editingDBConnection.readWrite { transaction in + Logger.info("\(self.logTag) marking all upgrades as seen.") + ExperienceUpgradeFinder.shared.markAllAsSeen(transaction: transaction) + } + super.dismiss(animated: flag, completion: completion) + } + func didTapDismissButton(sender: UIButton) { Logger.debug("\(TAG) in \(#function)") self.dismiss(animated: true) diff --git a/Signal/src/ViewControllers/HomeViewController.m b/Signal/src/ViewControllers/HomeViewController.m index fd6148776f..329c73a1e9 100644 --- a/Signal/src/ViewControllers/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeViewController.m @@ -47,7 +47,6 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; @property (nonatomic) UISegmentedControl *segmentedControl; @property (nonatomic) id previewingContext; @property (nonatomic) NSSet *blockedPhoneNumberSet; -@property (nonatomic) BOOL hasShownAnyUnseenUpgradeExperiences; @property (nonatomic) BOOL isViewVisible; @property (nonatomic) BOOL isAppInBackground; @@ -287,6 +286,13 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; [self updateBarButtonItems]; } +- (void)viewDidAppear:(BOOL)animated +{ + [super viewDidAppear:animated]; + + [self displayAnyUnseenUpgradeExperience]; +} + - (void)updateBarButtonItems { const CGFloat kBarButtonSize = 44; @@ -510,19 +516,6 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; }); }]; } - - // We want to show the user the upgrade experience as soon as the app is visible to them. - // It cannot go in viewDidAppear, which is called while the app is in the background if - // we were launched from a voip notification. - if (!self.hasShownAnyUnseenUpgradeExperiences) { - dispatch_async(dispatch_get_main_queue(), ^{ - if ([[UIApplication sharedApplication] applicationState] != UIApplicationStateActive) { - return; - } - [self displayAnyUnseenUpgradeExperience]; - self.hasShownAnyUnseenUpgradeExperiences = YES; - }); - } } #pragma mark - startup @@ -532,21 +525,12 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; OWSAssertIsOnMainThread(); __block NSArray *unseenUpgrades; - [self.editingDbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { + [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { unseenUpgrades = [ExperienceUpgradeFinder.sharedManager allUnseenWithTransaction:transaction]; }]; return unseenUpgrades; } -- (void)markAllUpgradeExperiencesAsSeen -{ - OWSAssertIsOnMainThread(); - - [self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { - [ExperienceUpgradeFinder.sharedManager markAllAsSeenWithTransaction:transaction]; - }]; -} - - (void)displayAnyUnseenUpgradeExperience { OWSAssertIsOnMainThread(); @@ -556,11 +540,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState }; if (unseenUpgrades.count > 0) { ExperienceUpgradesPageViewController *experienceUpgradeViewController = [[ExperienceUpgradesPageViewController alloc] initWithExperienceUpgrades:unseenUpgrades]; - [self presentViewController:experienceUpgradeViewController - animated:YES - completion:^{ - [self markAllUpgradeExperiencesAsSeen]; - }]; + [self presentViewController:experienceUpgradeViewController animated:YES completion:nil]; } else if (!self.hasBeenPresented && [ProfileViewController shouldDisplayProfileViewOnLaunch]) { [ProfileViewController presentForUpgradeOrNag:self]; } else { diff --git a/SignalMessaging/environment/OWSSounds.h b/SignalMessaging/environment/OWSSounds.h index 99d40ccfc9..506560d137 100644 --- a/SignalMessaging/environment/OWSSounds.h +++ b/SignalMessaging/environment/OWSSounds.h @@ -20,7 +20,7 @@ typedef NS_ENUM(NSUInteger, OWSSound) { OWSSound_Popcorn, OWSSound_Pulse, OWSSound_Synth, - OWSSound_ClassicNotification, + OWSSound_SignalClassic, // Ringtone Sounds OWSSound_Opening, diff --git a/SignalMessaging/environment/OWSSounds.m b/SignalMessaging/environment/OWSSounds.m index 60acb38718..0c7e29ba48 100644 --- a/SignalMessaging/environment/OWSSounds.m +++ b/SignalMessaging/environment/OWSSounds.m @@ -74,8 +74,8 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob @(OWSSound_Keys), @(OWSSound_Popcorn), @(OWSSound_Pulse), + @(OWSSound_SignalClassic), @(OWSSound_Synth), - @(OWSSound_ClassicNotification), ]; } @@ -112,7 +112,7 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob return @"Pulse"; case OWSSound_Synth: return @"Synth"; - case OWSSound_ClassicNotification: + case OWSSound_SignalClassic: return @"Signal Classic"; // Call Audio @@ -172,7 +172,7 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob return (quiet ? @"pulse-quiet.aifc" : @"pulse.aifc"); case OWSSound_Synth: return (quiet ? @"synth-quiet.aifc" : @"synth.aifc"); - case OWSSound_ClassicNotification: + case OWSSound_SignalClassic: return (quiet ? @"classic-quiet.aifc" : @"classic.aifc"); // Ringtone Sounds diff --git a/SignalMessaging/environment/migrations/OWS107LegacySounds.m b/SignalMessaging/environment/migrations/OWS107LegacySounds.m index 2c3214edb9..20cb6c48a8 100644 --- a/SignalMessaging/environment/migrations/OWS107LegacySounds.m +++ b/SignalMessaging/environment/migrations/OWS107LegacySounds.m @@ -22,7 +22,7 @@ static NSString *const OWS107LegacySoundsMigrationId = @"107"; { OWSAssert(transaction); - [OWSSounds setGlobalNotificationSound:OWSSound_ClassicNotification transaction:transaction]; + [OWSSounds setGlobalNotificationSound:OWSSound_SignalClassic transaction:transaction]; } @end