From 8d86a271d8de761241c568bf82386481a62689e4 Mon Sep 17 00:00:00 2001 From: Sam Symons Date: Tue, 12 Dec 2023 12:38:43 -0800 Subject: [PATCH] Release Branch PR: Fix waitlist notification prompt (#1958) Task/Issue URL: https://app.asana.com/0/1205634442726166/1206144535098820/f Description: This PR cherry picks a main branch PR to the release branch for inclusion in this week's release. --- DuckDuckGo/Waitlist/Models/WaitlistViewModel.swift | 13 +++++++++++++ .../Views/WaitlistViewControllerPresenter.swift | 2 ++ UnitTests/Waitlist/WaitlistViewModelTests.swift | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/DuckDuckGo/Waitlist/Models/WaitlistViewModel.swift b/DuckDuckGo/Waitlist/Models/WaitlistViewModel.swift index 15989403e7..5be2d26fe1 100644 --- a/DuckDuckGo/Waitlist/Models/WaitlistViewModel.swift +++ b/DuckDuckGo/Waitlist/Models/WaitlistViewModel.swift @@ -70,16 +70,19 @@ final class WaitlistViewModel: ObservableObject { private let notificationService: NotificationService private var termsAndConditionActionHandler: WaitlistTermsAndConditionsActionHandler private let featureSetupHandler: WaitlistFeatureSetupHandler + private let showNotificationSuccessState: Bool init(waitlistRequest: WaitlistRequest, waitlistStorage: WaitlistStorage, notificationService: NotificationService, notificationPermissionState: NotificationPermissionState = .notDetermined, + showNotificationSuccessState: Bool, termsAndConditionActionHandler: WaitlistTermsAndConditionsActionHandler, featureSetupHandler: WaitlistFeatureSetupHandler) { self.waitlistRequest = waitlistRequest self.waitlistStorage = waitlistStorage self.notificationService = notificationService + self.showNotificationSuccessState = showNotificationSuccessState self.termsAndConditionActionHandler = termsAndConditionActionHandler self.featureSetupHandler = featureSetupHandler if waitlistStorage.getWaitlistTimestamp() != nil, waitlistStorage.getWaitlistInviteCode() == nil { @@ -97,6 +100,7 @@ final class WaitlistViewModel: ObservableObject { convenience init(waitlist: Waitlist, notificationPermissionState: NotificationPermissionState = .notDetermined, + showNotificationSuccessState: Bool, termsAndConditionActionHandler: WaitlistTermsAndConditionsActionHandler, featureSetupHandler: WaitlistFeatureSetupHandler) { let waitlistType = type(of: waitlist) @@ -105,6 +109,7 @@ final class WaitlistViewModel: ObservableObject { waitlistStorage: WaitlistKeychainStore(waitlistIdentifier: waitlistType.identifier, keychainAppGroup: waitlistType.keychainAppGroup), notificationService: UNUserNotificationCenter.current(), notificationPermissionState: notificationPermissionState, + showNotificationSuccessState: showNotificationSuccessState, termsAndConditionActionHandler: termsAndConditionActionHandler, featureSetupHandler: featureSetupHandler ) @@ -196,6 +201,14 @@ final class WaitlistViewModel: ObservableObject { await checkNotificationPermissions() } } + + if showNotificationSuccessState { + self.viewState = .joinedWaitlist(.notificationAllowed) + } else { + Task { + await perform(action: .close) + } + } } private func openAppNotificationSettings() { diff --git a/DuckDuckGo/Waitlist/Views/WaitlistViewControllerPresenter.swift b/DuckDuckGo/Waitlist/Views/WaitlistViewControllerPresenter.swift index 04c606a3a3..afee252fc8 100644 --- a/DuckDuckGo/Waitlist/Views/WaitlistViewControllerPresenter.swift +++ b/DuckDuckGo/Waitlist/Views/WaitlistViewControllerPresenter.swift @@ -54,6 +54,7 @@ struct NetworkProtectionWaitlistViewControllerPresenter: WaitlistViewControllerP DispatchQueue.main.async { let viewModel = WaitlistViewModel(waitlist: NetworkProtectionWaitlist(), notificationPermissionState: state, + showNotificationSuccessState: true, termsAndConditionActionHandler: NetworkProtectionWaitlistTermsAndConditionsActionHandler(), featureSetupHandler: NetworkProtectionWaitlistFeatureSetupHandler()) @@ -103,6 +104,7 @@ struct DataBrokerProtectionWaitlistViewControllerPresenter: WaitlistViewControll DispatchQueue.main.async { let viewModel = WaitlistViewModel(waitlist: DataBrokerProtectionWaitlist(), notificationPermissionState: state, + showNotificationSuccessState: false, termsAndConditionActionHandler: DataBrokerProtectionWaitlistTermsAndConditionsActionHandler(), featureSetupHandler: DataBrokerProtectionWaitlistFeatureSetupHandler()) diff --git a/UnitTests/Waitlist/WaitlistViewModelTests.swift b/UnitTests/Waitlist/WaitlistViewModelTests.swift index 4fa29bb5b3..0f2ecdd9de 100644 --- a/UnitTests/Waitlist/WaitlistViewModelTests.swift +++ b/UnitTests/Waitlist/WaitlistViewModelTests.swift @@ -32,6 +32,7 @@ final class WaitlistViewModelTests: XCTestCase { let viewModel = WaitlistViewModel(waitlistRequest: request, waitlistStorage: storage, notificationService: MockNotificationService(), + showNotificationSuccessState: true, termsAndConditionActionHandler: MockWaitlistTermsAndConditionsActionHandler(), featureSetupHandler: MockWaitlistFeatureSetupHandler()) @@ -50,6 +51,7 @@ final class WaitlistViewModelTests: XCTestCase { let viewModel = WaitlistViewModel(waitlistRequest: request, waitlistStorage: storage, notificationService: notificationService, + showNotificationSuccessState: true, termsAndConditionActionHandler: MockWaitlistTermsAndConditionsActionHandler(), featureSetupHandler: MockWaitlistFeatureSetupHandler()) @@ -70,6 +72,7 @@ final class WaitlistViewModelTests: XCTestCase { let viewModel = WaitlistViewModel(waitlistRequest: request, waitlistStorage: storage, notificationService: notificationService, + showNotificationSuccessState: true, termsAndConditionActionHandler: MockWaitlistTermsAndConditionsActionHandler(), featureSetupHandler: MockWaitlistFeatureSetupHandler()) @@ -89,6 +92,7 @@ final class WaitlistViewModelTests: XCTestCase { let viewModel = WaitlistViewModel(waitlistRequest: request, waitlistStorage: storage, notificationService: notificationService, + showNotificationSuccessState: true, termsAndConditionActionHandler: MockWaitlistTermsAndConditionsActionHandler(), featureSetupHandler: MockWaitlistFeatureSetupHandler()) @@ -113,6 +117,7 @@ final class WaitlistViewModelTests: XCTestCase { let viewModel = WaitlistViewModel(waitlistRequest: request, waitlistStorage: storage, notificationService: notificationService, + showNotificationSuccessState: true, termsAndConditionActionHandler: MockWaitlistTermsAndConditionsActionHandler(), featureSetupHandler: MockWaitlistFeatureSetupHandler())