mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Fix issue on setting avatar on a room.
We deleted the just added avatar because `withState {}` is asynchronous
This commit is contained in:
parent
5c7a5fab94
commit
de39a17247
@ -8,7 +8,7 @@ Improvements 🙌:
|
|||||||
-
|
-
|
||||||
|
|
||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
-
|
- Fix issue when updating the avatar of a room
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
@ -153,20 +153,20 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleSetAvatarAction(action: RoomSettingsAction.SetAvatarAction) {
|
private fun handleSetAvatarAction(action: RoomSettingsAction.SetAvatarAction) {
|
||||||
deletePendingAvatar()
|
setState {
|
||||||
setState { copy(avatarAction = action.avatarAction) }
|
deletePendingAvatar(this)
|
||||||
}
|
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() } }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
private fun cancel() {
|
||||||
deletePendingAvatar()
|
withState { deletePendingAvatar(it) }
|
||||||
|
|
||||||
_viewEvents.post(RoomSettingsViewEvents.GoBack)
|
_viewEvents.post(RoomSettingsViewEvents.GoBack)
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
|
|
||||||
when (val avatarAction = state.avatarAction) {
|
when (val avatarAction = state.avatarAction) {
|
||||||
RoomSettingsViewState.AvatarAction.None -> Unit
|
RoomSettingsViewState.AvatarAction.None -> Unit
|
||||||
RoomSettingsViewState.AvatarAction.DeleteAvatar -> {
|
RoomSettingsViewState.AvatarAction.DeleteAvatar -> {
|
||||||
operationList.add(room.rx().deleteAvatar())
|
operationList.add(room.rx().deleteAvatar())
|
||||||
}
|
}
|
||||||
is RoomSettingsViewState.AvatarAction.UpdateAvatar -> {
|
is RoomSettingsViewState.AvatarAction.UpdateAvatar -> {
|
||||||
@ -209,8 +209,10 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
.subscribe(
|
.subscribe(
|
||||||
{
|
{
|
||||||
postLoading(false)
|
postLoading(false)
|
||||||
setState { copy(newHistoryVisibility = null) }
|
setState {
|
||||||
deletePendingAvatar()
|
deletePendingAvatar(this)
|
||||||
|
copy(newHistoryVisibility = null)
|
||||||
|
}
|
||||||
_viewEvents.post(RoomSettingsViewEvents.Success)
|
_viewEvents.post(RoomSettingsViewEvents.Success)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user