diff --git a/lib/domain/app_state/settings/update_profile_success.dart b/lib/domain/app_state/settings/update_profile_success.dart index eebecda062..5291f166ca 100644 --- a/lib/domain/app_state/settings/update_profile_success.dart +++ b/lib/domain/app_state/settings/update_profile_success.dart @@ -8,14 +8,22 @@ class UpdateProfileInitial extends Success { class UpdateProfileSuccess extends Success { final Uri? avatar; final String? displayName; - final bool isDeleteAvatar; const UpdateProfileSuccess({ this.avatar, this.displayName, - this.isDeleteAvatar = false, }); @override - List get props => [avatar, displayName, isDeleteAvatar]; + List get props => [avatar, displayName]; +} + +class DeleteProfileSuccess extends Success { + final String? displayName; + + const DeleteProfileSuccess({ + this.displayName, + }); + @override + List get props => [displayName]; } diff --git a/lib/domain/usecase/settings/update_profile_interactor.dart b/lib/domain/usecase/settings/update_profile_interactor.dart index ff4f7aa7d3..ac921c2995 100644 --- a/lib/domain/usecase/settings/update_profile_interactor.dart +++ b/lib/domain/usecase/settings/update_profile_interactor.dart @@ -30,11 +30,18 @@ class UpdateProfileInteractor { displayName, ); } + if (isDeleteAvatar) { + yield Right( + DeleteProfileSuccess( + displayName: displayName, + ), + ); + return; + } yield Right( UpdateProfileSuccess( displayName: displayName, avatar: avatarUrl, - isDeleteAvatar: isDeleteAvatar, ), ); } catch (e) { diff --git a/lib/pages/settings_dashboard/settings_profile/settings_profile.dart b/lib/pages/settings_dashboard/settings_profile/settings_profile.dart index 00938a36b7..31ddfcd4fe 100644 --- a/lib/pages/settings_dashboard/settings_profile/settings_profile.dart +++ b/lib/pages/settings_dashboard/settings_profile/settings_profile.dart @@ -455,12 +455,25 @@ class SettingsProfileController extends State avatarUrl: success.avatar ?? currentProfile.value?.avatarUrl, ); _sendAccountDataEvent(profile: newProfile); - if (!success.isDeleteAvatar) { - isEditedProfileNotifier.toggle(); - } + isEditedProfileNotifier.toggle(); _getCurrentProfile(client, isUpdated: true); TwakeDialog.hideLoadingDialog(context); } + + if (success is DeleteProfileSuccess) { + final newProfile = Profile( + userId: client.userID!, + displayName: success.displayName ?? displayName, + avatarUrl: null, + ); + _sendAccountDataEvent(profile: newProfile); + isEditedProfileNotifier.toggle(); + _getCurrentProfile(client, isUpdated: true); + TwakeDialog.hideLoadingDialog(context); + pickAvatarUIState.value = Right( + DeleteAvatarUIStateSuccess(), + ); + } }, ); } diff --git a/lib/presentation/model/pick_avatar_state.dart b/lib/presentation/model/pick_avatar_state.dart index 139b630333..5f21d37987 100644 --- a/lib/presentation/model/pick_avatar_state.dart +++ b/lib/presentation/model/pick_avatar_state.dart @@ -38,3 +38,10 @@ class GetAvatarBigSizeUIStateFailure extends Failure { @override List get props => []; } + +class DeleteAvatarUIStateSuccess extends PickAvatarState { + DeleteAvatarUIStateSuccess(); + + @override + List get props => []; +}