Ensure the user sees the experience upgrade

Don't mark it as seen until it is dismissed.

// FREEBIE
pull/1/head
Michael Kirk 7 years ago
parent 5739f074ae
commit 51ae936555

@ -490,12 +490,15 @@ class ExperienceUpgradesPageViewController: OWSViewController, UIPageViewControl
let pageViewController: UIPageViewController let pageViewController: UIPageViewController
let editingDBConnection: YapDatabaseConnection
// MARK: - Initializers // MARK: - Initializers
required init(experienceUpgrades: [ExperienceUpgrade]) { required init(experienceUpgrades: [ExperienceUpgrade]) {
self.experienceUpgrades = experienceUpgrades self.experienceUpgrades = experienceUpgrades
setPageControlAppearance() setPageControlAppearance()
self.editingDBConnection = TSStorageManager.shared().newDatabaseConnection()
self.pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil) self.pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
super.init(nibName: nil, bundle: nil) super.init(nibName: nil, bundle: nil)
self.pageViewController.dataSource = self self.pageViewController.dataSource = self
@ -505,12 +508,7 @@ class ExperienceUpgradesPageViewController: OWSViewController, UIPageViewControl
@available(*, unavailable, message:"unavailable, use initWithExperienceUpgrade instead") @available(*, unavailable, message:"unavailable, use initWithExperienceUpgrade instead")
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
assert(false) fatalError("unimplemented")
// 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
} }
// MARK: - View lifecycle // MARK: - View lifecycle
@ -679,6 +677,16 @@ class ExperienceUpgradesPageViewController: OWSViewController, UIPageViewControl
allViewControllers.append(viewController) 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) { func didTapDismissButton(sender: UIButton) {
Logger.debug("\(TAG) in \(#function)") Logger.debug("\(TAG) in \(#function)")
self.dismiss(animated: true) self.dismiss(animated: true)

@ -47,7 +47,6 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
@property (nonatomic) UISegmentedControl *segmentedControl; @property (nonatomic) UISegmentedControl *segmentedControl;
@property (nonatomic) id previewingContext; @property (nonatomic) id previewingContext;
@property (nonatomic) NSSet<NSString *> *blockedPhoneNumberSet; @property (nonatomic) NSSet<NSString *> *blockedPhoneNumberSet;
@property (nonatomic) BOOL hasShownAnyUnseenUpgradeExperiences;
@property (nonatomic) BOOL isViewVisible; @property (nonatomic) BOOL isViewVisible;
@property (nonatomic) BOOL isAppInBackground; @property (nonatomic) BOOL isAppInBackground;
@ -291,16 +290,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
{ {
[super viewDidAppear:animated]; [super viewDidAppear:animated];
// Keep in mind viewDidAppear is called while the app is in the background if the app was [self displayAnyUnseenUpgradeExperience];
// launched by a voip notification. This is fine - it will remain visible to the user
// when they eventually launch the app, but we shouldn't make any changes assuming
// the user has *seen* the upgrade experience at this point.
if (!self.hasShownAnyUnseenUpgradeExperiences) {
dispatch_async(dispatch_get_main_queue(), ^{
[self displayAnyUnseenUpgradeExperience];
self.hasShownAnyUnseenUpgradeExperiences = YES;
});
}
} }
- (void)updateBarButtonItems - (void)updateBarButtonItems
@ -535,21 +525,12 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
__block NSArray<ExperienceUpgrade *> *unseenUpgrades; __block NSArray<ExperienceUpgrade *> *unseenUpgrades;
[self.editingDbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
unseenUpgrades = [ExperienceUpgradeFinder.sharedManager allUnseenWithTransaction:transaction]; unseenUpgrades = [ExperienceUpgradeFinder.sharedManager allUnseenWithTransaction:transaction];
}]; }];
return unseenUpgrades; return unseenUpgrades;
} }
- (void)markAllUpgradeExperiencesAsSeen
{
OWSAssertIsOnMainThread();
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
[ExperienceUpgradeFinder.sharedManager markAllAsSeenWithTransaction:transaction];
}];
}
- (void)displayAnyUnseenUpgradeExperience - (void)displayAnyUnseenUpgradeExperience
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
@ -559,11 +540,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
if (unseenUpgrades.count > 0) { if (unseenUpgrades.count > 0) {
ExperienceUpgradesPageViewController *experienceUpgradeViewController = ExperienceUpgradesPageViewController *experienceUpgradeViewController =
[[ExperienceUpgradesPageViewController alloc] initWithExperienceUpgrades:unseenUpgrades]; [[ExperienceUpgradesPageViewController alloc] initWithExperienceUpgrades:unseenUpgrades];
[self presentViewController:experienceUpgradeViewController [self presentViewController:experienceUpgradeViewController animated:YES completion:nil];
animated:YES
completion:^{
[self markAllUpgradeExperiencesAsSeen];
}];
} else if (!self.hasBeenPresented && [ProfileViewController shouldDisplayProfileViewOnLaunch]) { } else if (!self.hasBeenPresented && [ProfileViewController shouldDisplayProfileViewOnLaunch]) {
[ProfileViewController presentForUpgradeOrNag:self]; [ProfileViewController presentForUpgradeOrNag:self];
} else { } else {

Loading…
Cancel
Save