Require the user to pick a display name

This commit is contained in:
Niels Andriesse 2019-10-11 13:19:57 +11:00
parent 533b00dab5
commit bd62ad099d
3 changed files with 17 additions and 20 deletions

View File

@ -6,7 +6,7 @@ final class DisplayNameVC : OnboardingBaseViewController {
result.textColor = Theme.primaryColor
result.font = UIFont.ows_dynamicTypeBodyClamped
result.textAlignment = .center
let placeholder = NSMutableAttributedString(string: NSLocalizedString("Display Name (Optional)", comment: ""))
let placeholder = NSMutableAttributedString(string: NSLocalizedString("Display Name", comment: ""))
placeholder.addAttribute(.foregroundColor, value: Theme.placeholderColor, range: NSRange(location: 0, length: placeholder.length))
result.attributedPlaceholder = placeholder
result.tintColor = UIColor.lokiGreen()
@ -14,11 +14,6 @@ final class DisplayNameVC : OnboardingBaseViewController {
result.keyboardAppearance = .dark
return result
}()
private var normalizedUserName: String? {
let result = userNameTextField.text!.ows_stripped()
return !result.isEmpty ? result : nil
}
override func viewDidLoad() {
super.viewDidLoad()
@ -59,16 +54,16 @@ final class DisplayNameVC : OnboardingBaseViewController {
}
@objc private func handleNextButtonPressed() {
if let normalizedName = normalizedUserName {
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"))
}
let displayName = userNameTextField.text!.ows_stripped()
guard !displayName.isEmpty else {
return OWSAlerts.showErrorAlert(message: NSLocalizedString("Please pick a display name", comment: ""))
}
guard !OWSProfileManager.shared().isProfileNameTooLong(displayName) else {
return OWSAlerts.showErrorAlert(message: NSLocalizedString("Please pick a shorter display name", comment: ""))
}
TSAccountManager.sharedInstance().didRegister()
UserDefaults.standard.set(true, forKey: "didUpdateForMainnet")
onboardingController.verificationDidComplete(fromView: self)
if let normalizedName = normalizedUserName {
OWSProfileManager.shared().updateLocalProfileName(normalizedName, avatarImage: nil, success: { }, failure: { }) // Try to save the user name but ignore the result
}
OWSProfileManager.shared().updateLocalProfileName(displayName, avatarImage: nil, success: { }, failure: { }) // Try to save the user name but ignore the result
}
}

View File

@ -393,12 +393,13 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
__weak ProfileViewController *weakSelf = self;
NSString *normalizedProfileName = [self normalizedProfileName];
if (normalizedProfileName.length == 0) {
return [OWSAlerts showErrorAlertWithMessage:NSLocalizedString(@"Please pick a display name", @"")];
}
if ([OWSProfileManager.sharedManager isProfileNameTooLong:normalizedProfileName]) {
[OWSAlerts
showErrorAlertWithMessage:NSLocalizedString(@"PROFILE_VIEW_ERROR_PROFILE_NAME_TOO_LONG",
@"Error message shown when user tries to update profile with a profile name "
@"that is too long.")];
return;
return [OWSAlerts showErrorAlertWithMessage:NSLocalizedString(@"Please pick a shorter display name", @"")];
}
[LKAnalytics.shared track:@"Display Name Updated"];

View File

@ -2547,7 +2547,7 @@
"Loki Messenger can let you know when you get a message (and who it is from)" = "Loki Messenger can let you know when you get a message (and who it is from)";
"Create Your Loki Messenger Account" = "Create Your Loki Messenger Account";
"Enter a name to be shown to your contacts" = "Enter a name to be shown to your contacts";
"Display Name (Optional)" = "Display Name (Optional)";
"Display Name" = "Display Name";
"Type an optional password for added security" = "Type an optional password for added security";
"Password (Optional)" = "Password (Optional)";
"Next" = "Next";
@ -2590,7 +2590,6 @@
"Your Seed" = "Your Seed";
"Unlock Loki Messenger's screen using Touch ID, Face ID, or your iOS device passcode. You can still answer incoming calls and receive message notifications while Screen Lock is enabled. Loki Messenger's notification settings allow you to customize the information that is displayed." = "Unlock Loki Messenger's screen using Touch ID, Face ID, or your iOS device passcode. You can still answer incoming calls and receive message notifications while Screen Lock is enabled. Loki Messenger's notification settings allow you to customize the information that is displayed.";
"Prevent Loki Messenger previews from appearing in the app switcher." = "Prevent Loki Messenger previews from appearing in the app switcher.";
"Display Name" = "Display Name";
"Loki Messenger" = "Loki Messenger";
"Privacy Policy" = "Privacy Policy";
"New Conversation" = "New Conversation";
@ -2636,3 +2635,5 @@
"Your device has been linked successfully" = "Your device has been linked successfully";
"Link" = "Link";
"Anonymous" = "Anonymous";
"Please pick a shorter display name" = "Please pick a shorter display name";
"Please pick a display name" = "Please pick a display name";