|
|
@ -223,22 +223,50 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
- (void)updateProfile
|
|
|
|
- (void)updateProfile
|
|
|
|
{
|
|
|
|
{
|
|
|
|
__weak ProfileViewController *weakSelf = self;
|
|
|
|
__weak ProfileViewController *weakSelf = self;
|
|
|
|
[OWSProfileManager.sharedManager updateLocalProfileName:self.nameTextField.text
|
|
|
|
|
|
|
|
avatarImage:self.avatar
|
|
|
|
// Show an activity indicator to block the UI during the profile upload.
|
|
|
|
success:^{
|
|
|
|
UIAlertController *alertController = [UIAlertController
|
|
|
|
[weakSelf.navigationController popViewControllerAnimated:YES];
|
|
|
|
alertControllerWithTitle:NSLocalizedString(@"PROFILE_VIEW_SAVING",
|
|
|
|
}
|
|
|
|
@"Alert title that indicates the user's profile view is being saved.")
|
|
|
|
failure:^{
|
|
|
|
message:nil
|
|
|
|
[OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"")
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
message:NSLocalizedString(@"PROFILE_VIEW_ERROR_UPDATE_FAILED",
|
|
|
|
|
|
|
|
@"Error message shown when a profile update fails.")];
|
|
|
|
[self presentViewController:alertController
|
|
|
|
}];
|
|
|
|
animated:YES
|
|
|
|
|
|
|
|
completion:^{
|
|
|
|
|
|
|
|
[OWSProfileManager.sharedManager updateLocalProfileName:[self normalizedProfileName]
|
|
|
|
|
|
|
|
avatarImage:self.avatar
|
|
|
|
|
|
|
|
success:^{
|
|
|
|
|
|
|
|
[alertController dismissViewControllerAnimated:NO
|
|
|
|
|
|
|
|
completion:^{
|
|
|
|
|
|
|
|
[weakSelf.navigationController
|
|
|
|
|
|
|
|
popViewControllerAnimated:YES];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
failure:^{
|
|
|
|
|
|
|
|
[alertController
|
|
|
|
|
|
|
|
dismissViewControllerAnimated:NO
|
|
|
|
|
|
|
|
completion:^{
|
|
|
|
|
|
|
|
[OWSAlerts
|
|
|
|
|
|
|
|
showAlertWithTitle:NSLocalizedString(
|
|
|
|
|
|
|
|
@"ALERT_ERROR_TITLE", @"")
|
|
|
|
|
|
|
|
message:
|
|
|
|
|
|
|
|
NSLocalizedString(
|
|
|
|
|
|
|
|
@"PROFILE_VIEW_ERROR_UPDATE_FAILED",
|
|
|
|
|
|
|
|
@"Error message shown when a "
|
|
|
|
|
|
|
|
@"profile update fails.")];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (NSString *)normalizedProfileName
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return [self.nameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - UITextFieldDelegate
|
|
|
|
#pragma mark - UITextFieldDelegate
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: This logic resides in both RegistrationViewController and here.
|
|
|
|
|
|
|
|
// We should refactor it out into a utility function.
|
|
|
|
|
|
|
|
- (BOOL)textField:(UITextField *)textField
|
|
|
|
- (BOOL)textField:(UITextField *)textField
|
|
|
|
shouldChangeCharactersInRange:(NSRange)range
|
|
|
|
shouldChangeCharactersInRange:(NSRange)range
|
|
|
|
replacementString:(NSString *)insertionText
|
|
|
|
replacementString:(NSString *)insertionText
|
|
|
|