mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 13:38:49 +03:00
Delete temporary file if user change again the room avatar
This commit is contained in:
parent
4887f678c5
commit
f5e46df309
1 changed files with 11 additions and 2 deletions
|
@ -142,7 +142,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
override fun handle(action: RoomSettingsAction) {
|
||||
when (action) {
|
||||
is RoomSettingsAction.EnableEncryption -> handleEnableEncryption()
|
||||
is RoomSettingsAction.SetAvatarAction -> setState { copy(avatarAction = action.avatarAction) }
|
||||
is RoomSettingsAction.SetAvatarAction -> handleSetAvatarAction(action)
|
||||
is RoomSettingsAction.SetRoomName -> setState { copy(newName = action.newName) }
|
||||
is RoomSettingsAction.SetRoomTopic -> setState { copy(newTopic = action.newTopic) }
|
||||
is RoomSettingsAction.SetRoomHistoryVisibility -> setState { copy(newHistoryVisibility = action.visibility) }
|
||||
|
@ -152,12 +152,21 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||
}.exhaustive
|
||||
}
|
||||
|
||||
private fun cancel() {
|
||||
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() } }
|
||||
}
|
||||
}
|
||||
|
||||
private fun cancel() {
|
||||
deletePendingAvatar()
|
||||
|
||||
_viewEvents.post(RoomSettingsViewEvents.GoBack)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue