diff --git a/Signal/src/Profiles/OWSProfileManager.h b/Signal/src/Profiles/OWSProfileManager.h index 4b8829dff..9040033a7 100644 --- a/Signal/src/Profiles/OWSProfileManager.h +++ b/Signal/src/Profiles/OWSProfileManager.h @@ -45,6 +45,8 @@ extern const NSUInteger kOWSProfileManager_MaxAvatarDiameter; success:(void (^)())successBlock failure:(void (^)())failureBlock; +- (BOOL)isProfileNameTooLong:(nullable NSString *)profileName; + #pragma mark - Profile Whitelist #ifdef DEBUG diff --git a/Signal/src/Profiles/OWSProfileManager.m b/Signal/src/Profiles/OWSProfileManager.m index bfde411ee..7dc1ac680 100644 --- a/Signal/src/Profiles/OWSProfileManager.m +++ b/Signal/src/Profiles/OWSProfileManager.m @@ -850,11 +850,6 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; { OWSAssert(contactRecipientIds); - // TODO: The persisted whitelist could either be: - // - // * Just users manually added to the whitelist. - // * Also include users auto-added by, for example, being in the user's - // contacts or when the user initiates a 1:1 conversation with them, etc. [self addUsersToProfileWhitelist:contactRecipientIds]; } @@ -1198,6 +1193,14 @@ const NSUInteger kOWSProfileManager_MaxAvatarDiameter = 640; 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 { NSData *nameData = [name dataUsingEncoding:NSUTF8StringEncoding]; diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index f862d6a57..b84fc8ed3 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -369,6 +369,15 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat { __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. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"PROFILE_VIEW_SAVING", @@ -379,7 +388,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat [self presentViewController:alertController animated:YES completion:^{ - [OWSProfileManager.sharedManager updateLocalProfileName:[self normalizedProfileName] + [OWSProfileManager.sharedManager updateLocalProfileName:normalizedProfileName avatarImage:self.avatar success:^{ [alertController dismissViewControllerAnimated:NO diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index ee221eb3f..dc0785757 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1090,6 +1090,9 @@ /* Label for action that clear's the user's profile 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. */ "PROFILE_VIEW_ERROR_UPDATE_FAILED" = "Profile update failed."; @@ -1114,9 +1117,6 @@ /* Alert title that indicates the user's profile view is being saved. */ "PROFILE_VIEW_SAVING" = "Saving..."; -/* Button to skip the profile view in the registration workflow. */ -"PROFILE_VIEW_SKIP_BUTTON" = "Skip"; - /* Title for the profile view. */ "PROFILE_VIEW_TITLE" = "Profile";