-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19710 from wordpress-mobile/feature/cmf-remove-ex…
…port-flag-after-import Jetpack Migration: Provide a path for JP to trigger data export in WP
- Loading branch information
Showing
11 changed files
with
354 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
WordPress/Classes/Utility/Universal Links/Migration/MigrationDeepLinkRouter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/// A router that specifically handles deeplinks. | ||
/// Note that the capability of this router is very limited; it can only handle up to one path component (e.g.: `wordpress://intent`). | ||
/// | ||
/// This is meant to be used during the WP->JP migratory period. Once we decide to move on from this phase, this class may be removed. | ||
/// | ||
struct MigrationDeepLinkRouter: LinkRouter { | ||
|
||
let routes: [Route] | ||
|
||
/// when this is set, the router ensures that the URL has a scheme that matches this value. | ||
private var scheme: String? = nil | ||
|
||
init(routes: [Route]) { | ||
self.routes = routes | ||
} | ||
|
||
init(scheme: String?, routes: [Route]) { | ||
self.init(routes: routes) | ||
self.scheme = scheme | ||
} | ||
|
||
init(urlForScheme: URL?, routes: [Route]) { | ||
self.init(scheme: urlForScheme?.scheme, routes: routes) | ||
} | ||
|
||
func canHandle(url: URL) -> Bool { | ||
// if the scheme is set, check if the URL fulfills the requirement. | ||
if let scheme, url.scheme != scheme { | ||
return false | ||
} | ||
|
||
/// deeplinks have their paths start at `host`, unlike universal links. | ||
/// e.g. wordpress://intent -> "intent" is the URL's host. | ||
/// | ||
/// Ensure that the deeplink URL has a "host" that we can run against the `routes`' path. | ||
guard let deepLinkPath = url.host else { | ||
return false | ||
} | ||
|
||
return routes | ||
.map { $0.path.removingPrefix("/") } | ||
.contains { $0 == deepLinkPath } | ||
} | ||
|
||
func handle(url: URL, shouldTrack track: Bool = false, source: DeepLinkSource? = nil) { | ||
guard let deepLinkPath = url.host, | ||
let route = routes.filter({ $0.path.removingPrefix("/") == deepLinkPath }).first else { | ||
return | ||
} | ||
|
||
// there's no need to pass any arguments or parameters since most of the migration deeplink routes are standalone. | ||
route.action.perform([:], source: nil, router: self) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
WordPress/Classes/Utility/Universal Links/Migration/WordPressExportRoute.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// Triggers the data export process on WordPress. | ||
/// | ||
/// Note: this is only meant to be used in WordPress! | ||
/// | ||
struct WordPressExportRoute: Route { | ||
let path = "/export-213" | ||
let section: DeepLinkSection? = nil | ||
var action: NavigationAction { | ||
return self | ||
} | ||
} | ||
|
||
extension WordPressExportRoute: NavigationAction { | ||
func perform(_ values: [String: String], source: UIViewController?, router: LinkRouter) { | ||
guard AppConfiguration.isWordPress else { | ||
return | ||
} | ||
|
||
ContentMigrationCoordinator.shared.startAndDo { _ in | ||
// Regardless of the result, redirect the user back to Jetpack. | ||
let jetpackUrl: URL? = { | ||
var components = URLComponents() | ||
components.scheme = JetpackNotificationMigrationService.jetpackScheme | ||
return components.url | ||
}() | ||
|
||
guard let url = jetpackUrl, | ||
UIApplication.shared.canOpenURL(url) else { | ||
DDLogError("WordPressExportRoute: Cannot redirect back to the Jetpack app.") | ||
return | ||
} | ||
|
||
UIApplication.shared.open(url) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
...ck/Classes/ViewRelated/WordPress-to-Jetpack Migration/Common/MigratableStateTracker.swift
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.