Show an error when profile name is too long.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 3cccf92757
commit e8a6ca1c22

@ -45,6 +45,8 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter;
success:(void (^)())successBlock success:(void (^)())successBlock
failure:(void (^)())failureBlock; failure:(void (^)())failureBlock;
- (BOOL)isProfileNameTooLong:(nullable NSString *)profileName;
#pragma mark - Profile Whitelist #pragma mark - Profile Whitelist
#ifdef DEBUG #ifdef DEBUG

@ -1198,6 +1198,14 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640;
return [self encryptProfileData:data profileKey:self.localProfileKey]; return [self encryptProfileData:data profileKey:self.localProfileKey];
} }
- (BOOL)isProfileNameTooLong:(nullable NSString *)profileName
{
OWSAssert([NSThread isMainThread]);
NSData *nameData = [profileName dataUsingEncoding:NSUTF8StringEncoding];
return nameData.length > kOWSProfileManager_NameDataLength;
}
- (nullable NSData *)encryptProfileNameWithUnpaddedName:(NSString *)name - (nullable NSData *)encryptProfileNameWithUnpaddedName:(NSString *)name
{ {
NSData *nameData = [name dataUsingEncoding:NSUTF8StringEncoding]; NSData *nameData = [name dataUsingEncoding:NSUTF8StringEncoding];

@ -369,6 +369,15 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
{ {
__weak ProfileViewController *weakSelf = self; __weak ProfileViewController *weakSelf = self;
NSString *normalizedProfileName = [self normalizedProfileName];
if ([OWSProfileManager.sharedManager isProfileNameTooLong:normalizedProfileName]) {
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
message: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;
}
// Show an activity indicator to block the UI during the profile upload. // Show an activity indicator to block the UI during the profile upload.
UIAlertController *alertController = [UIAlertController UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"PROFILE_VIEW_SAVING", alertControllerWithTitle:NSLocalizedString(@"PROFILE_VIEW_SAVING",
@ -379,7 +388,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat
[self presentViewController:alertController [self presentViewController:alertController
animated:YES animated:YES
completion:^{ completion:^{
[OWSProfileManager.sharedManager updateLocalProfileName:[self normalizedProfileName] [OWSProfileManager.sharedManager updateLocalProfileName:normalizedProfileName
avatarImage:self.avatar avatarImage:self.avatar
success:^{ success:^{
[alertController dismissViewControllerAnimated:NO [alertController dismissViewControllerAnimated:NO

@ -1090,6 +1090,9 @@
/* Label for action that clear's the user's profile avatar */ /* Label for action that clear's the user's profile avatar */
"PROFILE_VIEW_CLEAR_AVATAR" = "Clear Avatar"; "PROFILE_VIEW_CLEAR_AVATAR" = "Clear Avatar";
/* Error message shown when user tries to update profile with a profile name that is too long. */
"PROFILE_VIEW_ERROR_PROFILE_NAME_TOO_LONG" = "Your profile name is too long.";
/* Error message shown when a profile update fails. */ /* Error message shown when a profile update fails. */
"PROFILE_VIEW_ERROR_UPDATE_FAILED" = "Profile update failed."; "PROFILE_VIEW_ERROR_UPDATE_FAILED" = "Profile update failed.";
@ -1114,9 +1117,6 @@
/* Alert title that indicates the user's profile view is being saved. */ /* Alert title that indicates the user's profile view is being saved. */
"PROFILE_VIEW_SAVING" = "Saving..."; "PROFILE_VIEW_SAVING" = "Saving...";
/* Button to skip the profile view in the registration workflow. */
"PROFILE_VIEW_SKIP_BUTTON" = "Skip";
/* Title for the profile view. */ /* Title for the profile view. */
"PROFILE_VIEW_TITLE" = "Profile"; "PROFILE_VIEW_TITLE" = "Profile";

Loading…
Cancel
Save