Skip to content
Draft
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
59 changes: 43 additions & 16 deletions WordPress/Classes/System/WordPressAppDelegate+openURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ import WordPressData
import WordPressShared

@objc extension WordPressAppDelegate {
public func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
public func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
handle(url: url)
}

/// Routes an inbound URL (custom scheme deep links, magic-login, migration, OAuth).
/// Reused by both the legacy app-lifecycle path and `WordPressSceneDelegate`.
@discardableResult
func handle(url: URL) -> Bool {
let redactedURL = LoggingURLRedactor.redactedURL(url)
DDLogInfo("Application launched with URL: \(redactedURL)")

Expand All @@ -19,10 +29,13 @@ import WordPressShared
}

/// WordPress only. Handle deeplink from JP that requests data export.
let wordPressExportRouter = MigrationDeepLinkRouter(urlForScheme: URL(string: AppScheme.wordpressMigrationV1.rawValue),
routes: [WordPressExportRoute()])
let wordPressExportRouter = MigrationDeepLinkRouter(
urlForScheme: URL(string: AppScheme.wordpressMigrationV1.rawValue),
routes: [WordPressExportRoute()]
)
if AppConfiguration.isWordPress,
wordPressExportRouter.canHandle(url: url) {
wordPressExportRouter.canHandle(url: url)
{
wordPressExportRouter.handle(url: url)
return true
}
Expand Down Expand Up @@ -59,7 +72,8 @@ import WordPressShared
private func handleViewPost(url: URL) -> Bool {
guard let params = url.queryItems,
let blogId = params.intValue(of: "blogId"),
let postId = params.intValue(of: "postId") else {
let postId = params.intValue(of: "postId")
else {
return false
}
RootViewCoordinator.sharedPresenter.showReader(path: .post(postID: postId, siteID: blogId))
Expand All @@ -71,7 +85,8 @@ import WordPressShared

guard let params = url.queryItems,
let siteId = params.intValue(of: "siteId"),
let blog = try? Blog.lookup(withID: siteId, in: ContextManager.shared.mainContext) else {
let blog = try? Blog.lookup(withID: siteId, in: ContextManager.shared.mainContext)
else {
return false
}

Expand Down Expand Up @@ -110,7 +125,8 @@ import WordPressShared
private func handleDebugging(url: URL) -> Bool {
guard let params = url.queryItems,
let debugType = params.value(of: "type"),
let debugKey = params.value(of: "key") else {
let debugKey = params.value(of: "key")
else {
return false
}

Expand All @@ -131,8 +147,9 @@ import WordPressShared
/// This is mostly a return of the old functionality: https://github.com/wordpress-mobile/WordPress-iOS/blob/d89b7ec712be1f2e11fb1228089771a25f5587c5/WordPress/Classes/ViewRelated/System/WPTabBarController.m#L388```
private func handleNewPost(url: URL) -> Bool {
guard let params = url.queryItems,
let contentRaw = params.value(of: NewPostKey.content) else {
return false
let contentRaw = params.value(of: NewPostKey.content)
else {
return false
}

let title = params.value(of: NewPostKey.title)
Expand All @@ -156,7 +173,10 @@ import WordPressShared

RootViewCoordinator.sharedPresenter.rootViewController.present(postVC, animated: true, completion: nil)

WPAppAnalytics.track(.editorCreatedPost, withProperties: [WPAppAnalyticsKeyTapSource: "url_scheme", WPAppAnalyticsKeyPostType: "post"])
WPAppAnalytics.track(
.editorCreatedPost,
withProperties: [WPAppAnalyticsKeyTapSource: "url_scheme", WPAppAnalyticsKeyPostType: "post"]
)

return true
}
Expand All @@ -169,8 +189,9 @@ import WordPressShared
/// text. May support other formats, such as HTML or Markdown in the future.
private func handleNewPage(url: URL) -> Bool {
guard let params = url.queryItems,
let contentRaw = params.value(of: NewPostKey.content) else {
return false
let contentRaw = params.value(of: NewPostKey.content)
else {
return false
}

let title = params.value(of: NewPostKey.title)
Expand All @@ -183,7 +204,12 @@ import WordPressShared
// Should more formats be accepted be accepted in the future, this line would have to be expanded to accomodate it.
let contentEscaped = contentRaw.escapeHtmlNamedEntities()

RootViewCoordinator.sharedPresenter.showPageEditor(blog: blog, title: title, content: contentEscaped, source: "url_scheme")
RootViewCoordinator.sharedPresenter.showPageEditor(
blog: blog,
title: title,
content: contentEscaped,
source: "url_scheme"
)

return true
}
Expand All @@ -198,7 +224,7 @@ import WordPressShared

private extension Array where Element == URLQueryItem {
func value(of key: String) -> String? {
return self.first(where: { $0.name == key })?.value
self.first(where: { $0.name == key })?.value
}

func intValue(of key: String) -> Int? {
Expand All @@ -213,8 +239,9 @@ private extension URL {
var queryItems: [URLQueryItem]? {
guard let components = URLComponents(url: self, resolvingAgainstBaseURL: false),
let queryItems = components.queryItems,
!queryItems.isEmpty else {
return nil
!queryItems.isEmpty
else {
return nil
}
return queryItems
}
Expand Down
Loading