From b64bb79254b9db8113cda7116306667d05f856d2 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Mon, 29 Apr 2019 14:35:12 +1000 Subject: [PATCH] Minor refactoring --- ...boardingAccountDetailsViewController.swift | 30 ++++++++----------- .../Registration/OnboardingController.swift | 4 +-- .../OnboardingPublicKeyViewController.swift | 15 +++++----- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/Signal/src/ViewControllers/Registration/OnboardingAccountDetailsViewController.swift b/Signal/src/ViewControllers/Registration/OnboardingAccountDetailsViewController.swift index 7be08f50f..af5f9097d 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingAccountDetailsViewController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingAccountDetailsViewController.swift @@ -23,11 +23,10 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle result.isSecureTextEntry = true return result }() - + private var normalizedName: String? { - get { - return displayNameTextField.text?.ows_stripped() - } + let result = displayNameTextField.text!.ows_stripped() + return !result.isEmpty ? result : nil } override func viewDidLoad() { @@ -73,21 +72,16 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle displayNameTextField.becomeFirstResponder() } - @objc private func goToSeedStep(profileName: String? = nil) { - onboardingController.pushPublicKeyViewController(from: self, profileName: profileName) - } - @objc private func updateProfile() { - guard let normalizedName = self.normalizedName else { - self.goToSeedStep() - return - } - - if (OWSProfileManager.shared().isProfileNameTooLong(normalizedName)) { - OWSAlerts.showErrorAlert(message: NSLocalizedString("PROFILE_VIEW_ERROR_PROFILE_NAME_TOO_LONG", comment: "Error message shown when user tries to update profile with a profile name that is too long")) - return + if let normalizedName = normalizedName { + guard !OWSProfileManager.shared().isProfileNameTooLong(normalizedName) else { + return OWSAlerts.showErrorAlert(message: NSLocalizedString("PROFILE_VIEW_ERROR_PROFILE_NAME_TOO_LONG", comment: "Error message shown when user tries to update profile with a profile name that is too long")) + } } - - self.goToSeedStep(profileName: normalizedName) + goToSeedStep() + } + + @objc private func goToSeedStep() { + onboardingController.pushPublicKeyViewController(from: self, userName: normalizedName) } } diff --git a/Signal/src/ViewControllers/Registration/OnboardingController.swift b/Signal/src/ViewControllers/Registration/OnboardingController.swift index 4ebb142a3..b76a0378d 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingController.swift @@ -128,9 +128,9 @@ public class OnboardingController: NSObject { viewController.navigationController?.pushViewController(accountDetailsVC, animated: true) } - func pushPublicKeyViewController(from viewController: UIViewController, profileName: String?) { + func pushPublicKeyViewController(from viewController: UIViewController, userName: String?) { AssertIsOnMainThread() - let publicKeyVC = OnboardingPublicKeyViewController(onboardingController: self, profileName: profileName) + let publicKeyVC = OnboardingPublicKeyViewController(onboardingController: self, userName: userName) viewController.navigationController?.pushViewController(publicKeyVC, animated: true) } diff --git a/Signal/src/ViewControllers/Registration/OnboardingPublicKeyViewController.swift b/Signal/src/ViewControllers/Registration/OnboardingPublicKeyViewController.swift index f2ad6cc53..aa072280b 100644 --- a/Signal/src/ViewControllers/Registration/OnboardingPublicKeyViewController.swift +++ b/Signal/src/ViewControllers/Registration/OnboardingPublicKeyViewController.swift @@ -5,7 +5,7 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController { private var keyPair: ECKeyPair! { didSet { updateMnemonic() } } private var hexEncodedPublicKey: String! private var mnemonic: String! { didSet { mnemonicLabel.text = mnemonic } } - private var profileName: String? + private var userName: String? private lazy var mnemonicLabel: UILabel = { let result = createExplanationLabel(text: "") @@ -17,10 +17,9 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController { return result }() - @objc - public init(onboardingController: OnboardingController, profileName: String?) { - super.init(onboardingController: onboardingController); - self.profileName = profileName + init(onboardingController: OnboardingController, userName: String?) { + super.init(onboardingController: onboardingController) + self.userName = userName } override public func viewDidLoad() { @@ -81,10 +80,10 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController { strongSelf.onboardingController.verificationDidComplete(fromView: strongSelf) } - if let name = self.profileName { + if let userName = userName { // Try save the profile name - OWSProfileManager.shared().updateLocalProfileName(name, avatarImage: nil, success: verificationComplete, failure: { - Logger.warn("Failed to set profile name") + OWSProfileManager.shared().updateLocalProfileName(userName, avatarImage: nil, success: verificationComplete, failure: { + Logger.warn("Failed to set user name") verificationComplete() }) } else {