This repository was archived by the owner on Feb 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Site address discovery #666
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
061dcd5
Update extension for storyboard and UIViewController to instantiate w…
itsmeichigo 1120d94
Add new delegate method for troubleshooting a site
itsmeichigo 1be9c7c
Make navigation controller optional in `troubleshootSite`
itsmeichigo a094ce6
Add new initializer for `SiteAddressViewController` to support troubl…
itsmeichigo d9667c4
Add new method to support displaying the site address UI for troubles…
itsmeichigo 1f1b5a6
Bump version in podspec
itsmeichigo e1d5159
Make the default extension public
itsmeichigo 2c8b170
Refactor: rename needsTroubleShooting to isSiteDiscovery and update t…
itsmeichigo 811c11c
Check site validity before checking for WordPress
itsmeichigo 3a31819
Move error handling to the main thread
itsmeichigo 23a5324
Stop loading state when encountering non-existent URL error
itsmeichigo 72a7652
Increase timeout for site check
itsmeichigo 17c962e
Update error message for non-existent site address
itsmeichigo eb58755
Merge branch 'trunk' into wcios/site-address-discovery
itsmeichigo 7cdd0c6
Trigger delegate method when check WP fails
itsmeichigo 032faba
Add comment to clarify parameters for troubleshootSite
itsmeichigo 90de21d
Bump podspec version
itsmeichigo 9ac61bf
Merge branch 'trunk' into wcios/site-address-discovery
itsmeichigo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -22,8 +22,8 @@ enum Storyboard: String { | |
| /// Returns a view controller from a Storyboard | ||
| /// assuming the identifier is the same as the class name. | ||
| /// | ||
| func instantiateViewController<T: NSObject>(ofClass classType: T.Type) -> T? { | ||
| func instantiateViewController<T: NSObject>(ofClass classType: T.Type, creator: ((NSCoder) -> UIViewController?)? = nil) -> T? { | ||
| let identifier = classType.classNameWithoutNamespaces | ||
| return instance.instantiateViewController(withIdentifier: identifier) as? T | ||
| return instance.instantiateViewController(identifier: identifier, creator: creator) as? T | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL this 🙇 |
||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -28,6 +28,20 @@ final class SiteAddressViewController: LoginViewController { | |
| /// should show an activity indicator. | ||
| private var viewIsLoading: Bool = false | ||
|
|
||
| /// Whether the protocol method `troubleshootSite` should be triggered after site info is fetched. | ||
| /// | ||
| private let isSiteDiscovery: Bool | ||
|
|
||
| init?(isSiteDiscovery: Bool, coder: NSCoder) { | ||
| self.isSiteDiscovery = isSiteDiscovery | ||
| super.init(coder: coder) | ||
| } | ||
|
|
||
| required init?(coder: NSCoder) { | ||
| self.isSiteDiscovery = false | ||
| super.init(coder: coder) | ||
| } | ||
|
|
||
| // MARK: - Actions | ||
| @IBAction func handleContinueButtonTapped(_ sender: NUXButton) { | ||
| tracker.track(click: .submit) | ||
|
|
@@ -59,7 +73,11 @@ final class SiteAddressViewController: LoginViewController { | |
| override func viewDidAppear(_ animated: Bool) { | ||
| super.viewDidAppear(animated) | ||
|
|
||
| tracker.set(flow: .loginWithSiteAddress) | ||
| if isSiteDiscovery { | ||
| tracker.set(flow: .siteDiscovery) | ||
| } else { | ||
| tracker.set(flow: .loginWithSiteAddress) | ||
| } | ||
|
|
||
| if isMovingToParent { | ||
| tracker.track(step: .start) | ||
|
|
@@ -416,8 +434,42 @@ private extension SiteAddressViewController { | |
|
|
||
| configureViewLoading(true) | ||
|
|
||
| guard let url = URL(string: loginFields.siteAddress) else { | ||
| configureViewLoading(false) | ||
| return displayError(message: Localization.invalidURL, moveVoiceOverFocus: true) | ||
| } | ||
|
|
||
| // Checks that the site exists | ||
| var request = URLRequest(url: url) | ||
| request.httpMethod = "HEAD" | ||
| request.timeoutInterval = 10.0 // waits for 10 seconds | ||
| let task = URLSession.shared.dataTask(with: request) { [weak self] _, _, error in | ||
| DispatchQueue.main.async { [weak self] in | ||
| guard let self = self else { return } | ||
|
|
||
| if let error = error { | ||
| self.configureViewLoading(false) | ||
|
|
||
| if self.authenticationDelegate.shouldHandleError(error) { | ||
| self.authenticationDelegate.handleError(error) { customUI in | ||
| self.pushCustomUI(customUI) | ||
| } | ||
| return | ||
| } | ||
|
|
||
| return self.displayError(message: Localization.nonExistentSiteError, moveVoiceOverFocus: true) | ||
| } | ||
|
|
||
| // Proceeds to check for the site's WordPress | ||
| self.guessXMLRPCURL(for: self.loginFields.siteAddress) | ||
| } | ||
| } | ||
| task.resume() | ||
| } | ||
|
Comment on lines
+442
to
+468
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense! Added a PR here: wordpress-mobile/WordPress-iOS#19209. |
||
|
|
||
| func guessXMLRPCURL(for siteAddress: String) { | ||
| let facade = WordPressXMLRPCAPIFacade() | ||
| facade.guessXMLRPCURL(forSite: loginFields.siteAddress, success: { [weak self] (url) in | ||
| facade.guessXMLRPCURL(forSite: siteAddress, success: { [weak self] (url) in | ||
| // Success! We now know that we have a valid XML-RPC endpoint. | ||
| // At this point, we do NOT know if this is a WP.com site or a self-hosted site. | ||
| if let url = url { | ||
|
|
@@ -439,6 +491,11 @@ private extension SiteAddressViewController { | |
| // WordPressAuthenticator.track(.loginFailed, error: error) | ||
| self.configureViewLoading(false) | ||
|
|
||
| guard self.isSiteDiscovery == false else { | ||
| WordPressAuthenticator.shared.delegate?.troubleshootSite(nil, in: self.navigationController) | ||
| return | ||
| } | ||
|
|
||
| let err = self.originalErrorOrError(error: error as NSError) | ||
|
|
||
| /// Check if the host app wants to provide custom UI to handle the error. | ||
|
|
@@ -515,6 +572,11 @@ private extension SiteAddressViewController { | |
| loginFields.siteAddress = verifiedSiteAddress | ||
| } | ||
|
|
||
| guard isSiteDiscovery == false else { | ||
| WordPressAuthenticator.shared.delegate?.troubleshootSite(siteInfo, in: navigationController) | ||
| return | ||
| } | ||
|
|
||
| guard siteInfo?.isWPCom == false else { | ||
| showGetStarted() | ||
| return | ||
|
|
@@ -611,3 +673,14 @@ private extension SiteAddressViewController { | |
| present(alertController, animated: true) | ||
| } | ||
| } | ||
|
|
||
| private extension SiteAddressViewController { | ||
| enum Localization { | ||
| static let invalidURL = NSLocalizedString( | ||
| "Invalid URL. Please double-check and try again.", | ||
| comment: "Error message shown when the input URL is invalid.") | ||
| static let nonExistentSiteError = NSLocalizedString( | ||
| "Cannot access the site at this address. Please double-check and try again.", | ||
| comment: "Error message shown when the input URL does not point to an existing site.") | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.