Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,55 +65,69 @@ private extension MigrationHeaderConfiguration {
case .welcome:
return welcomeSecondaryDescription(plural: multiSite)
case .notifications:
return JetpackNotificationMigrationService.shared.isMigrationSupported ? notificationsSecondaryDescription : nil
return nil
case .done:
return nil
case .dismiss:
return nil
}
}

static let welcomeTitle = NSLocalizedString("migration.welcome.title",
value: "Welcome to Jetpack!",
comment: "The title in the migration welcome screen")

static let notificationsTitle = NSLocalizedString("migration.notifications.title",
value: "Allow notifications to keep up with your site",
comment: "Title of the migration notifications screen.")

static let doneTitle = NSLocalizedString("migration.done.title",
value: "Thanks for switching to Jetpack!",
comment: "Title of the migration done screen.")

static let welcomePrimaryDescription = NSLocalizedString("migration.welcome.primaryDescription",
value: "It looks like you’re switching from the WordPress app.",
comment: "The primary description in the migration welcome screen")

static let notificationsPrimaryDescription = NSLocalizedString("migration.notifications.primaryDescription",
value: "You’ll get all the same notifications but now they’ll come from the Jetpack app.",
comment: "Primary description in the migration notifications screen.")

static let donePrimaryDescription = NSLocalizedString("migration.done.primaryDescription",
value: "We’ve transferred all your data and settings. Everything is right where you left it.",
comment: "Primary description in the migration done screen.")

static let doneSecondaryDescription = NSLocalizedString("migration.done.secondaryDescription", value: "It's time to continue your WordPress journey on the Jetpack app!", comment: "Secondary description (second paragraph) in the migration done screen.")

static let notificationsSecondaryDescription = NSLocalizedString("migration.notifications.secondaryDescription",
value: "We’ll disable notifications for the WordPress app.",
comment: "Secondary description in the migration notifications screen")
static let welcomeTitle = NSLocalizedString(
"migration.welcome.title",
value: "Welcome to Jetpack!",
comment: "The title in the migration welcome screen"
)

static let notificationsTitle = NSLocalizedString(
"migration.notifications.title",
value: "Allow notifications to keep up with your site",
comment: "Title of the migration notifications screen."
)

static let doneTitle = NSLocalizedString(
"migration.done.title",
value: "Thanks for switching to Jetpack!",
comment: "Title of the migration done screen."
)

static let welcomePrimaryDescription = NSLocalizedString(
"migration.welcome.primaryDescription",
value: "It looks like you’re switching from the WordPress app.",
comment: "The primary description in the migration welcome screen"
)

static let notificationsPrimaryDescription = NSLocalizedString(
"migration.notifications.primaryDescription",
value: "You’ll get all the same notifications but now they’ll come from the Jetpack app.",
comment: "Primary description in the migration notifications screen."
)

static let donePrimaryDescription = NSLocalizedString(
"migration.done.primaryDescription",
value: "We’ve transferred all your data and settings. Everything is right where you left it.",
comment: "Primary description in the migration done screen."
)

static let doneSecondaryDescription = NSLocalizedString(
"migration.done.secondaryDescription",
value: "It's time to continue your WordPress journey on the Jetpack app!",
comment: "Secondary description (second paragraph) in the migration done screen."
)

static func welcomeSecondaryDescription(plural: Bool) -> String {
if plural {
return NSLocalizedString(
"migration.welcome.secondaryDescription.plural",
value: "We found your sites. Continue to transfer all your data and sign in to Jetpack automatically.",
value:
"We found your sites. Continue to transfer all your data and sign in to Jetpack automatically.",
comment: "The plural form of the secondary description in the migration welcome screen"
)
} else {
return NSLocalizedString(
"migration.welcome.secondaryDescription.singular",
value: "We found your site. Continue to transfer all your data and sign in to Jetpack automatically.",
value:
"We found your site. Continue to transfer all your data and sign in to Jetpack automatically.",
comment: "The singular form of the secondary description in the migration welcome screen"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ protocol JetpackNotificationMigrationServiceProtocol {
func shouldPresentNotifications() -> Bool
}

/// The service is created to support disabling WordPress notifications when Jetpack app enables notifications
/// The service uses URLScheme to determine from Jetpack app if WordPress app is installed, open it, disable notifications and come back to Jetpack app
/// This is a temporary solution to avoid duplicate notifications during the migration process from WordPress to Jetpack app
/// This service and its usage can be deleted once the migration is done
/// The service was created to support disabling WordPress notifications when the Jetpack app enables notifications,
/// as a temporary solution to avoid duplicate notifications during the migration process from WordPress to Jetpack app.
///
/// The Jetpack app no longer initiates this migration: launching the WordPress app just to disable its notifications
/// visibly bounced the user between apps (CMM-2224), and the WordPress app has been disabling its own notifications
/// on every launch since the Jetpack features removal. The WordPress-side URL handler is kept so older Jetpack
/// versions that still open `wordpressnotificationmigration://` get redirected back instead of stranding the user.
final class JetpackNotificationMigrationService: JetpackNotificationMigrationServiceProtocol {
private let remoteNotificationRegister: RemoteNotificationRegister
private let featureFlagStore: RemoteFeatureFlagStore
Expand All @@ -20,10 +23,9 @@ final class JetpackNotificationMigrationService: JetpackNotificationMigrationSer
static let wordPressScheme = "wordpressnotificationmigration"
static let jetpackScheme = "jetpacknotificationmigration"
private let wordPressNotificationsToggledDefaultsKey = "wordPressNotificationsToggledDefaultsKey"
private let jetpackNotificationMigrationDefaultsKey = "jetpackNotificationMigrationDefaultsKey"

private var jetpackMigrationPreventDuplicateNotifications: Bool {
return RemoteFeatureFlag.jetpackMigrationPreventDuplicateNotifications.enabled(using: featureFlagStore)
RemoteFeatureFlag.jetpackMigrationPreventDuplicateNotifications.enabled(using: featureFlagStore)
}

private lazy var notificationSettingsService: NotificationSettingsService? = {
Expand Down Expand Up @@ -67,42 +69,26 @@ final class JetpackNotificationMigrationService: JetpackNotificationMigrationSer
}
}

/// Migration is supported if WordPress is compatible with the notification migration URLScheme
var isMigrationSupported: Bool {
guard let url = URL(string: "\(JetpackNotificationMigrationService.wordPressScheme)://") else {
return false
}

return UIApplication.shared.canOpenURL(url) && jetpackMigrationPreventDuplicateNotifications
}

/// disableWordPressNotificationsFromJetpack may get triggered multiple times from Jetpack app but it only needs to be executed the first time
private var isMigrationDone: Bool {
get {
return userDefaults.bool(forKey: jetpackNotificationMigrationDefaultsKey)
}
set {
userDefaults.setValue(newValue, forKey: jetpackNotificationMigrationDefaultsKey)
}
}

init(remoteNotificationRegister: RemoteNotificationRegister = UIApplication.shared,
featureFlagStore: RemoteFeatureFlagStore = RemoteFeatureFlagStore(),
userDefaults: UserDefaults = .standard,
isWordPress: Bool = AppConfiguration.isWordPress) {
init(
remoteNotificationRegister: RemoteNotificationRegister = UIApplication.shared,
featureFlagStore: RemoteFeatureFlagStore = RemoteFeatureFlagStore(),
userDefaults: UserDefaults = .standard,
isWordPress: Bool = AppConfiguration.isWordPress
) {
self.remoteNotificationRegister = remoteNotificationRegister
self.featureFlagStore = featureFlagStore
self.userDefaults = userDefaults
self.isWordPress = isWordPress
}

func shouldShowNotificationControl() -> Bool {
return jetpackMigrationPreventDuplicateNotifications && isWordPress
jetpackMigrationPreventDuplicateNotifications && isWordPress
}

func shouldPresentNotifications() -> Bool {
let notificationsDisabled = !JetpackFeaturesRemovalCoordinator.jetpackFeaturesEnabled()
let appMigrated = jetpackMigrationPreventDuplicateNotifications
let appMigrated =
jetpackMigrationPreventDuplicateNotifications
&& isWordPress
&& userDefaults.bool(forKey: wordPressNotificationsToggledDefaultsKey)
&& !wordPressNotificationsEnabled
Expand All @@ -115,26 +101,6 @@ final class JetpackNotificationMigrationService: JetpackNotificationMigrationSer
return !disableNotifications
}

// MARK: - Only executed on Jetpack app

func disableWordPressNotificationsFromJetpack() {
guard !isMigrationDone, jetpackMigrationPreventDuplicateNotifications, !isWordPress else {
return
}

let wordPressUrl: URL? = {
var components = URLComponents()
components.scheme = JetpackNotificationMigrationService.wordPressScheme
return components.url
}()

/// Open WordPress app to disable notifications
if let url = wordPressUrl, UIApplication.shared.canOpenURL(url) {
isMigrationDone = true
UIApplication.shared.open(url)
}
}

// MARK: - Only executed on WordPress app

func handleNotificationMigrationOnWordPress() -> Bool {
Expand All @@ -160,7 +126,9 @@ final class JetpackNotificationMigrationService: JetpackNotificationMigrationSer

// MARK: - Local notifications

private func cancelAllPendingWordPressLocalNotifications(notificationCenter: UNUserNotificationCenter = UNUserNotificationCenter.current()) {
private func cancelAllPendingWordPressLocalNotifications(
notificationCenter: UNUserNotificationCenter = UNUserNotificationCenter.current()
) {
if isWordPress {
notificationCenter.removeAllPendingNotificationRequests()
}
Expand All @@ -178,21 +146,25 @@ final class JetpackNotificationMigrationService: JetpackNotificationMigrationSer
}

private func rescheduleBloggingReminderNotifications() {
notificationSettingsService?.getAllSettings { [weak self] settings in
for setting in settings {
if let blog = setting.blog,
let schedule = self?.bloggingRemindersScheduler?.schedule(for: blog),
let time = self?.bloggingRemindersScheduler?.scheduledTime(for: blog) {
if schedule != .none {
self?.bloggingRemindersScheduler?.schedule(schedule, for: blog, time: time) { result in
if case .success = result {
BloggingRemindersFlow.setHasShownWeeklyRemindersFlow(for: blog)
}
notificationSettingsService?
.getAllSettings { [weak self] settings in
for setting in settings {
if let blog = setting.blog,
let schedule = self?.bloggingRemindersScheduler?.schedule(for: blog),
let time = self?.bloggingRemindersScheduler?.scheduledTime(for: blog)
{
if schedule != .none {
self?.bloggingRemindersScheduler?
.schedule(schedule, for: blog, time: time) { result in
if case .success = result {
BloggingRemindersFlow.setHasShownWeeklyRemindersFlow(for: blog)
}
}
}
}
}
} failure: { _ in
}
} failure: { _ in }
}
}

Expand Down
Loading