Skip to content

Commit

Permalink
Release Branch PR: Fix waitlist notification prompt (#1958)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
samsymons authored Dec 12, 2023
1 parent eb9f592 commit 8d86a27
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions DuckDuckGo/Waitlist/Models/WaitlistViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
)
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct NetworkProtectionWaitlistViewControllerPresenter: WaitlistViewControllerP
DispatchQueue.main.async {
let viewModel = WaitlistViewModel(waitlist: NetworkProtectionWaitlist(),
notificationPermissionState: state,
showNotificationSuccessState: true,
termsAndConditionActionHandler: NetworkProtectionWaitlistTermsAndConditionsActionHandler(),
featureSetupHandler: NetworkProtectionWaitlistFeatureSetupHandler())

Expand Down Expand Up @@ -103,6 +104,7 @@ struct DataBrokerProtectionWaitlistViewControllerPresenter: WaitlistViewControll
DispatchQueue.main.async {
let viewModel = WaitlistViewModel(waitlist: DataBrokerProtectionWaitlist(),
notificationPermissionState: state,
showNotificationSuccessState: false,
termsAndConditionActionHandler: DataBrokerProtectionWaitlistTermsAndConditionsActionHandler(),
featureSetupHandler: DataBrokerProtectionWaitlistFeatureSetupHandler())

Expand Down
5 changes: 5 additions & 0 deletions UnitTests/Waitlist/WaitlistViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class WaitlistViewModelTests: XCTestCase {
let viewModel = WaitlistViewModel(waitlistRequest: request,
waitlistStorage: storage,
notificationService: MockNotificationService(),
showNotificationSuccessState: true,
termsAndConditionActionHandler: MockWaitlistTermsAndConditionsActionHandler(),
featureSetupHandler: MockWaitlistFeatureSetupHandler())

Expand All @@ -50,6 +51,7 @@ final class WaitlistViewModelTests: XCTestCase {
let viewModel = WaitlistViewModel(waitlistRequest: request,
waitlistStorage: storage,
notificationService: notificationService,
showNotificationSuccessState: true,
termsAndConditionActionHandler: MockWaitlistTermsAndConditionsActionHandler(),
featureSetupHandler: MockWaitlistFeatureSetupHandler())

Expand All @@ -70,6 +72,7 @@ final class WaitlistViewModelTests: XCTestCase {
let viewModel = WaitlistViewModel(waitlistRequest: request,
waitlistStorage: storage,
notificationService: notificationService,
showNotificationSuccessState: true,
termsAndConditionActionHandler: MockWaitlistTermsAndConditionsActionHandler(),
featureSetupHandler: MockWaitlistFeatureSetupHandler())

Expand All @@ -89,6 +92,7 @@ final class WaitlistViewModelTests: XCTestCase {
let viewModel = WaitlistViewModel(waitlistRequest: request,
waitlistStorage: storage,
notificationService: notificationService,
showNotificationSuccessState: true,
termsAndConditionActionHandler: MockWaitlistTermsAndConditionsActionHandler(),
featureSetupHandler: MockWaitlistFeatureSetupHandler())

Expand All @@ -113,6 +117,7 @@ final class WaitlistViewModelTests: XCTestCase {
let viewModel = WaitlistViewModel(waitlistRequest: request,
waitlistStorage: storage,
notificationService: notificationService,
showNotificationSuccessState: true,
termsAndConditionActionHandler: MockWaitlistTermsAndConditionsActionHandler(),
featureSetupHandler: MockWaitlistFeatureSetupHandler())

Expand Down

0 comments on commit 8d86a27

Please sign in to comment.