Delete temporary file if user change again the room avatar
This commit is contained in:
parent
4887f678c5
commit
f5e46df309
@ -142,7 +142,7 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
override fun handle(action: RoomSettingsAction) {
|
override fun handle(action: RoomSettingsAction) {
|
||||||
when (action) {
|
when (action) {
|
||||||
is RoomSettingsAction.EnableEncryption -> handleEnableEncryption()
|
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.SetRoomName -> setState { copy(newName = action.newName) }
|
||||||
is RoomSettingsAction.SetRoomTopic -> setState { copy(newTopic = action.newTopic) }
|
is RoomSettingsAction.SetRoomTopic -> setState { copy(newTopic = action.newTopic) }
|
||||||
is RoomSettingsAction.SetRoomHistoryVisibility -> setState { copy(newHistoryVisibility = action.visibility) }
|
is RoomSettingsAction.SetRoomHistoryVisibility -> setState { copy(newHistoryVisibility = action.visibility) }
|
||||||
@ -152,12 +152,21 @@ class RoomSettingsViewModel @AssistedInject constructor(@Assisted initialState:
|
|||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cancel() {
|
private fun handleSetAvatarAction(action: RoomSettingsAction.SetAvatarAction) {
|
||||||
|
deletePendingAvatar()
|
||||||
|
setState { copy(avatarAction = action.avatarAction) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deletePendingAvatar() {
|
||||||
// Maybe delete the pending avatar
|
// Maybe delete the pending avatar
|
||||||
withState {
|
withState {
|
||||||
(it.avatarAction as? RoomSettingsViewState.AvatarAction.UpdateAvatar)
|
(it.avatarAction as? RoomSettingsViewState.AvatarAction.UpdateAvatar)
|
||||||
?.let { tryOrNull { it.newAvatarUri.toFile().delete() } }
|
?.let { tryOrNull { it.newAvatarUri.toFile().delete() } }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun cancel() {
|
||||||
|
deletePendingAvatar()
|
||||||
|
|
||||||
_viewEvents.post(RoomSettingsViewEvents.GoBack)
|
_viewEvents.post(RoomSettingsViewEvents.GoBack)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user