Skip to content

Commit d91cfe3

Browse files
authored
Merge pull request #19698 from wordpress-mobile/release/21.3
Merge 21.3 changes between first & second beta to trunk
2 parents f68a260 + b38bd88 commit d91cfe3

23 files changed

+513
-224
lines changed

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ abstract_target 'Apps' do
179179
## Gutenberg (React Native)
180180
## =====================
181181
##
182-
gutenberg tag: 'v1.85.0'
182+
gutenberg tag: 'v1.85.1'
183183

184184
## Third party libraries
185185
## =====================

Podfile.lock

Lines changed: 101 additions & 101 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Foundation
2+
3+
enum AppScheme: String {
4+
case wordpress = "wordpress://"
5+
case wordpressMigrationV1 = "wordpressmigration+v1://"
6+
}
7+
8+
extension UIApplication {
9+
func canOpen(app: AppScheme) -> Bool {
10+
guard let url = URL(string: app.rawValue) else {
11+
return false
12+
}
13+
return canOpenURL(url)
14+
}
15+
}

WordPress/Classes/Services/JetpackNotificationMigrationService.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ protocol JetpackNotificationMigrationServiceProtocol {
1111
final class JetpackNotificationMigrationService: JetpackNotificationMigrationServiceProtocol {
1212
private let remoteNotificationRegister: RemoteNotificationRegister
1313
private let featureFlagStore: RemoteFeatureFlagStore
14+
private let userDefaults: UserDefaults
1415
private let isWordPress: Bool
1516

1617
static let shared = JetpackNotificationMigrationService()
1718

1819
static let wordPressScheme = "wordpressnotificationmigration"
1920
static let jetpackScheme = "jetpacknotificationmigration"
21+
private let wordPressNotificationsToggledDefaultsKey = "wordPressNotificationsToggledDefaultsKey"
2022
private let jetpackNotificationMigrationDefaultsKey = "jetpackNotificationMigrationDefaultsKey"
2123

2224
private var jetpackMigrationPreventDuplicateNotifications: Bool {
@@ -38,6 +40,8 @@ final class JetpackNotificationMigrationService: JetpackNotificationMigrationSer
3840
}
3941

4042
set {
43+
userDefaults.set(true, forKey: wordPressNotificationsToggledDefaultsKey)
44+
4145
if newValue, isWordPress {
4246
remoteNotificationRegister.registerForRemoteNotifications()
4347
rescheduleLocalNotifications()
@@ -63,18 +67,20 @@ final class JetpackNotificationMigrationService: JetpackNotificationMigrationSer
6367
/// disableWordPressNotificationsFromJetpack may get triggered multiple times from Jetpack app but it only needs to be executed the first time
6468
private var isMigrationDone: Bool {
6569
get {
66-
return UserDefaults.standard.bool(forKey: jetpackNotificationMigrationDefaultsKey)
70+
return userDefaults.bool(forKey: jetpackNotificationMigrationDefaultsKey)
6771
}
6872
set {
69-
UserDefaults.standard.setValue(newValue, forKey: jetpackNotificationMigrationDefaultsKey)
73+
userDefaults.setValue(newValue, forKey: jetpackNotificationMigrationDefaultsKey)
7074
}
7175
}
7276

7377
init(remoteNotificationRegister: RemoteNotificationRegister = UIApplication.shared,
7478
featureFlagStore: RemoteFeatureFlagStore = RemoteFeatureFlagStore(),
79+
userDefaults: UserDefaults = .standard,
7580
isWordPress: Bool = AppConfiguration.isWordPress) {
7681
self.remoteNotificationRegister = remoteNotificationRegister
7782
self.featureFlagStore = featureFlagStore
83+
self.userDefaults = userDefaults
7884
self.isWordPress = isWordPress
7985
}
8086

@@ -85,6 +91,7 @@ final class JetpackNotificationMigrationService: JetpackNotificationMigrationSer
8591
func shouldPresentNotifications() -> Bool {
8692
let disableNotifications = jetpackMigrationPreventDuplicateNotifications
8793
&& isWordPress
94+
&& userDefaults.bool(forKey: wordPressNotificationsToggledDefaultsKey)
8895
&& !wordPressNotificationsEnabled
8996

9097
if disableNotifications {

WordPress/Classes/Stores/UserPersistentRepositoryUtility.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ private enum UPRUConstants {
1515
static let currentAnnouncementsKey = "currentAnnouncements"
1616
static let currentAnnouncementsDateKey = "currentAnnouncementsDate"
1717
static let announcementsVersionDisplayedKey = "announcementsVersionDisplayed"
18+
static let isJPContentImportCompleteKey = "jetpackContentImportComplete"
1819
}
1920

2021
protocol UserPersistentRepositoryUtility: AnyObject {
@@ -164,4 +165,13 @@ extension UserPersistentRepositoryUtility {
164165
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.announcementsVersionDisplayedKey)
165166
}
166167
}
168+
169+
var isJPContentImportComplete: Bool {
170+
get {
171+
return UserPersistentStoreFactory.instance().bool(forKey: UPRUConstants.isJPContentImportCompleteKey)
172+
}
173+
set {
174+
UserPersistentStoreFactory.instance().set(newValue, forKey: UPRUConstants.isJPContentImportCompleteKey)
175+
}
176+
}
167177
}

WordPress/Classes/System/WordPressAppDelegate.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ class WordPressAppDelegate: UIResponder, UIApplicationDelegate {
197197
uploadsManager.resume()
198198
updateFeatureFlags()
199199
updateRemoteConfig()
200+
201+
#if JETPACK
202+
if let windowManager = windowManager as? JetpackWindowManager,
203+
windowManager.shouldImportMigrationData {
204+
windowManager.importAndShowMigrationContent(nil, failureCompletion: nil)
205+
}
206+
#endif
200207
}
201208

202209
func applicationWillResignActive(_ application: UIApplication) {

WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ import Foundation
415415
case jetpackSiteCreationOverlayButtonTapped
416416
case jetpackSiteCreationOverlayDismissed
417417

418+
// WordPress to Jetpack Migration
419+
case migrationEmailTriggered
420+
case migrationEmailSent
421+
case migrationEmailFailed
422+
418423
/// A String that represents the event
419424
var value: String {
420425
switch self {
@@ -1123,6 +1128,15 @@ import Foundation
11231128
return "remove_site_creation_overlay_button_tapped"
11241129
case .jetpackSiteCreationOverlayDismissed:
11251130
return "remove_site_creation_overlay_dismissed"
1131+
1132+
// WordPress to Jetpack Migration
1133+
case .migrationEmailTriggered:
1134+
return "migration_email_triggered"
1135+
case .migrationEmailSent:
1136+
return "migration_email_sent"
1137+
case .migrationEmailFailed:
1138+
return "migration_email_failed"
1139+
11261140
} // END OF SWITCH
11271141
}
11281142

WordPress/Classes/Utility/Migration/ContentMigrationCoordinator.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ class ContentMigrationCoordinator {
88

99
// MARK: Dependencies
1010

11+
private let coreDataStack: CoreDataStack
1112
private let dataMigrator: ContentDataMigrating
1213
private let userPersistentRepository: UserPersistentRepository
1314
private let eligibilityProvider: ContentMigrationEligibilityProvider
1415

15-
init(dataMigrator: ContentDataMigrating = DataMigrator(),
16+
init(coreDataStack: CoreDataStack = ContextManager.shared,
17+
dataMigrator: ContentDataMigrating = DataMigrator(),
1618
userPersistentRepository: UserPersistentRepository = UserDefaults.standard,
1719
eligibilityProvider: ContentMigrationEligibilityProvider = AppConfiguration()) {
20+
self.coreDataStack = coreDataStack
1821
self.dataMigrator = dataMigrator
1922
self.userPersistentRepository = userPersistentRepository
2023
self.eligibilityProvider = eligibilityProvider
@@ -23,6 +26,7 @@ class ContentMigrationCoordinator {
2326
enum ContentMigrationCoordinatorError: Error {
2427
case ineligible
2528
case exportFailure
29+
case localDraftsNotSynced
2630
}
2731

2832
// MARK: Methods
@@ -41,7 +45,10 @@ class ContentMigrationCoordinator {
4145
return
4246
}
4347

44-
// TODO: Sync local post drafts here.
48+
guard isLocalPostsSynced() else {
49+
completion?(.failure(.localDraftsNotSynced))
50+
return
51+
}
4552

4653
dataMigrator.exportData { result in
4754
switch result {
@@ -78,6 +85,26 @@ class ContentMigrationCoordinator {
7885
}
7986
}
8087

88+
// MARK: - Preflights Local Draft Check
89+
90+
private extension ContentMigrationCoordinator {
91+
92+
func isLocalPostsSynced() -> Bool {
93+
let fetchRequest = NSFetchRequest<Post>(entityName: String(describing: Post.self))
94+
fetchRequest.predicate = NSPredicate(format: "remoteStatusNumber = %@ || remoteStatusNumber = %@ || remoteStatusNumber = %@ || remoteStatusNumber = %@",
95+
NSNumber(value: AbstractPostRemoteStatus.pushing.rawValue),
96+
NSNumber(value: AbstractPostRemoteStatus.failed.rawValue),
97+
NSNumber(value: AbstractPostRemoteStatus.local.rawValue),
98+
NSNumber(value: AbstractPostRemoteStatus.pushingMedia.rawValue))
99+
guard let count = try? coreDataStack.mainContext.count(for: fetchRequest) else {
100+
return false
101+
}
102+
103+
return count == 0
104+
}
105+
106+
}
107+
81108
// MARK: - Content Migration Eligibility Provider
82109

83110
protocol ContentMigrationEligibilityProvider {

WordPress/Classes/ViewRelated/Support/LogOutActionHandler.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ import UIKit
22

33
struct LogOutActionHandler {
44

5+
private weak var windowManager: WindowManager?
6+
7+
init(windowManager: WindowManager? = WordPressAppDelegate.shared?.windowManager) {
8+
self.windowManager = windowManager
9+
}
10+
511
func logOut(with viewController: UIViewController) {
612
let alert = UIAlertController(title: logOutAlertTitle, message: nil, preferredStyle: .alert)
713
alert.addActionWithTitle(Strings.alertCancelAction, style: .cancel)
814
alert.addActionWithTitle(Strings.alertLogoutAction, style: .destructive) { [weak viewController] _ in
915
viewController?.dismiss(animated: true) {
1016
AccountHelper.logOutDefaultWordPressComAccount()
17+
windowManager?.showSignInUI()
1118
}
1219
}
1320
viewController.present(alert, animated: true)

WordPress/Info.plist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@
477477
<array>
478478
<string>wordpress-oauth-v2</string>
479479
<string>${WPCOM_SCHEME}</string>
480+
<string>wordpressmigration+v1</string>
480481
<string>wordpressnotificationmigration</string>
481482
</array>
482483
</dict>

0 commit comments

Comments
 (0)