diff --git a/Signal/src/ViewControllers/AvatarViewHelper.h b/Signal/src/ViewControllers/AvatarViewHelper.h index 928164279..b640a0dc1 100644 --- a/Signal/src/ViewControllers/AvatarViewHelper.h +++ b/Signal/src/ViewControllers/AvatarViewHelper.h @@ -19,6 +19,14 @@ NS_ASSUME_NONNULL_BEGIN - (UIViewController *)fromViewController; +- (BOOL)hasClearAvatarAction; + +@optional + +- (NSString *)clearAvatarActionLabel; + +- (void)clearAvatar; + @end #pragma mark - diff --git a/Signal/src/ViewControllers/AvatarViewHelper.m b/Signal/src/ViewControllers/AvatarViewHelper.m index b88b4a00e..3a300e0c3 100644 --- a/Signal/src/ViewControllers/AvatarViewHelper.m +++ b/Signal/src/ViewControllers/AvatarViewHelper.m @@ -53,6 +53,15 @@ NS_ASSUME_NONNULL_BEGIN }]; [actionSheetController addAction:choosePictureAction]; + if (self.delegate.hasClearAvatarAction) { + UIAlertAction *clearAction = [UIAlertAction actionWithTitle:self.delegate.clearAvatarActionLabel + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *_Nonnull action) { + [self.delegate clearAvatar]; + }]; + [actionSheetController addAction:clearAction]; + } + [self.delegate.fromViewController presentViewController:actionSheetController animated:true completion:nil]; } diff --git a/Signal/src/ViewControllers/NewGroupViewController.m b/Signal/src/ViewControllers/NewGroupViewController.m index 83eb7f09f..4beb77bf9 100644 --- a/Signal/src/ViewControllers/NewGroupViewController.m +++ b/Signal/src/ViewControllers/NewGroupViewController.m @@ -626,6 +626,11 @@ const NSUInteger kNewGroupViewControllerAvatarWidth = 68; return self; } +- (BOOL)hasClearAvatarAction +{ + return NO; +} + #pragma mark - AddToGroupViewControllerDelegate - (void)recipientIdWasAdded:(NSString *)recipientId diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 18383a749..0f3fede74 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -272,7 +272,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)avatarActionSheetTitle { return NSLocalizedString( - @"PROFILE_AVATAR_ACTIONSHEET_TITLE", @"Action Sheet title prompting the user for a profile avatar"); + @"PROFILE_VIEW_AVATAR_ACTIONSHEET_TITLE", @"Action Sheet title prompting the user for a profile avatar"); } - (void)avatarDidChange:(UIImage *)image @@ -289,6 +289,21 @@ NS_ASSUME_NONNULL_BEGIN return self; } +- (BOOL)hasClearAvatarAction +{ + return YES; +} + +- (NSString *)clearAvatarActionLabel +{ + return NSLocalizedString(@"PROFILE_VIEW_CLEAR_AVATAR", @"Label for action that clear's the user's profile avatar"); +} + +- (void)clearAvatar +{ + self.avatar = nil; +} + #pragma mark - Logging + (NSString *)tag diff --git a/Signal/src/ViewControllers/UpdateGroupViewController.m b/Signal/src/ViewControllers/UpdateGroupViewController.m index 6b3f1eb93..0bf85eafc 100644 --- a/Signal/src/ViewControllers/UpdateGroupViewController.m +++ b/Signal/src/ViewControllers/UpdateGroupViewController.m @@ -507,6 +507,11 @@ NS_ASSUME_NONNULL_BEGIN return self; } +- (BOOL)hasClearAvatarAction +{ + return NO; +} + #pragma mark - AddToGroupViewControllerDelegate - (void)recipientIdWasAdded:(NSString *)recipientId diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 01fe53dc4..7c0b42729 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1037,7 +1037,7 @@ "PROCEED_BUTTON" = "Proceed"; /* Action Sheet title prompting the user for a profile avatar */ -"PROFILE_AVATAR_ACTIONSHEET_TITLE" = "Set Profile Avatar"; +"PROFILE_VIEW_AVATAR_ACTIONSHEET_TITLE" = "Set Profile Avatar"; /* Instructions for how to change the profile avatar. */ "PROFILE_VIEW_AVATAR_INSTRUCTIONS" = "Tap to Select Avatar"; @@ -1045,6 +1045,9 @@ /* Header title for the profile avatar field of the profile view. */ "PROFILE_VIEW_AVATAR_SECTION_HEADER" = "Avatar"; +/* Label for action that clear's the user's profile avatar */ +"PROFILE_VIEW_CLEAR_AVATAR" = "Clear Avatar"; + /* Default text for the profile name field of the profile view. */ "PROFILE_VIEW_NAME_DEFAULT_TEXT" = "Enter your name."; diff --git a/SignalServiceKit/src/Profiles/OWSProfilesManager.m b/SignalServiceKit/src/Profiles/OWSProfilesManager.m index 7eda6dd54..d110b7cf9 100644 --- a/SignalServiceKit/src/Profiles/OWSProfilesManager.m +++ b/SignalServiceKit/src/Profiles/OWSProfilesManager.m @@ -443,6 +443,8 @@ static const NSInteger kProfileKeyLength = 16; return profileAvatarsDirPath; } +// TODO: We may want to clean up this directory in the "orphan cleanup" logic. + #pragma mark - Notifications - (void)applicationDidBecomeActive:(NSNotification *)notification