From de39a17247185a7e682bdd9a79b6086559936c43 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 5 Nov 2020 16:09:04 +0100 Subject: [PATCH] Fix issue on setting avatar on a room. We deleted the just added avatar because `withState {}` is asynchronous --- CHANGES.md | 2 +- .../settings/RoomSettingsViewModel.kt | 28 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7fbf564393..c1e6bab185 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ Improvements 🙌: - Bugfix 🐛: - - + - Fix issue when updating the avatar of a room Translations 🗣: - diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt index 32d8f043c3..6bf88e755e 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsViewModel.kt @@ -153,20 +153,20 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: } private fun handleSetAvatarAction(action: RoomSettingsAction.SetAvatarAction) { - deletePendingAvatar() - setState { copy(avatarAction = action.avatarAction) } - } - - private fun deletePendingAvatar() { - // Maybe delete the pending avatar - withState { - (it.avatarAction as? RoomSettingsViewState.AvatarAction.UpdateAvatar) - ?.let { tryOrNull { it.newAvatarUri.toFile().delete() } } + setState { + deletePendingAvatar(this) + copy(avatarAction = action.avatarAction) } } + private fun deletePendingAvatar(state: RoomSettingsViewState) { + // Maybe delete the pending avatar + (state.avatarAction as? RoomSettingsViewState.AvatarAction.UpdateAvatar) + ?.let { tryOrNull { it.newAvatarUri.toFile().delete() } } + } + private fun cancel() { - deletePendingAvatar() + withState { deletePendingAvatar(it) } _viewEvents.post(RoomSettingsViewEvents.GoBack) } @@ -180,7 +180,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: when (val avatarAction = state.avatarAction) { RoomSettingsViewState.AvatarAction.None -> Unit - RoomSettingsViewState.AvatarAction.DeleteAvatar -> { + RoomSettingsViewState.AvatarAction.DeleteAvatar -> { operationList.add(room.rx().deleteAvatar()) } is RoomSettingsViewState.AvatarAction.UpdateAvatar -> { @@ -209,8 +209,10 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState: .subscribe( { postLoading(false) - setState { copy(newHistoryVisibility = null) } - deletePendingAvatar() + setState { + deletePendingAvatar(this) + copy(newHistoryVisibility = null) + } _viewEvents.post(RoomSettingsViewEvents.Success) }, {