Set loki profile name upon registration

pull/2/head
Mikunj 6 years ago
parent c26a5c9cdf
commit 8e5327f915

@ -24,6 +24,12 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle
return result
}()
private var normalizedName: String? {
get {
return displayNameTextField.text?.ows_stripped()
}
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Theme.backgroundColor
@ -36,7 +42,7 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle
let passwordLabel = createExplanationLabel(text: NSLocalizedString("Type an optional password for added security", comment: ""))
passwordLabel.accessibilityIdentifier = "onboarding.accountDetailsStep.passwordLabel"
let bottomSpacer = UIView.vStretchingSpacer()
let nextButton = button(title: NSLocalizedString("Next", comment: ""), selector: #selector(goToSeedStep))
let nextButton = button(title: NSLocalizedString("Next", comment: ""), selector: #selector(updateProfile))
nextButton.accessibilityIdentifier = "onboarding.accountDetailsStep.nextButton"
let stackView = UIStackView(arrangedSubviews: [
titleLabel,
@ -67,7 +73,21 @@ final class OnboardingAccountDetailsViewController : OnboardingBaseViewControlle
displayNameTextField.becomeFirstResponder()
}
@objc private func goToSeedStep() {
onboardingController.pushPublicKeyViewController(from: self)
@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
}
self.goToSeedStep(profileName: normalizedName)
}
}

@ -128,9 +128,9 @@ public class OnboardingController: NSObject {
viewController.navigationController?.pushViewController(accountDetailsVC, animated: true)
}
func pushPublicKeyViewController(from viewController: UIViewController) {
func pushPublicKeyViewController(from viewController: UIViewController, profileName: String?) {
AssertIsOnMainThread()
let publicKeyVC = OnboardingPublicKeyViewController(onboardingController: self)
let publicKeyVC = OnboardingPublicKeyViewController(onboardingController: self, profileName: profileName)
viewController.navigationController?.pushViewController(publicKeyVC, animated: true)
}

@ -5,6 +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 lazy var mnemonicLabel: UILabel = {
let result = createExplanationLabel(text: "")
@ -16,6 +17,12 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController {
return result
}()
@objc
public init(onboardingController: OnboardingController, profileName: String?) {
super.init(onboardingController: onboardingController);
self.profileName = profileName
}
override public func viewDidLoad() {
super.loadView()
setUpViewHierarchy()
@ -68,6 +75,21 @@ final class OnboardingPublicKeyViewController : OnboardingBaseViewController {
let accountManager = TSAccountManager.sharedInstance()
accountManager.phoneNumberAwaitingVerification = hexEncodedPublicKey
accountManager.didRegister()
onboardingController.verificationDidComplete(fromView: self)
let verificationComplete: () -> Void = { [weak self] in
guard let strongSelf = self else { return }
strongSelf.onboardingController.verificationDidComplete(fromView: strongSelf)
}
if let name = self.profileName {
// Try save the profile name
OWSProfileManager.shared().updateLocalProfileName(name, avatarImage: nil, success: verificationComplete, failure: {
Logger.warn("Failed to set profile name")
verificationComplete()
})
} else {
verificationComplete()
}
}
}

Loading…
Cancel
Save