From f5ae95d7f16bcdce7ad8b995c7c48fe30f11c5b0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 24 Nov 2020 08:34:01 +0100 Subject: [PATCH] Close form only if necessary --- .../roomprofile/alias/RoomAliasViewModel.kt | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewModel.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewModel.kt index ff9c023a21..3110c22e21 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewModel.kt @@ -164,7 +164,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo is RoomAliasAction.SetNewLocalAliasLocalPart -> handleSetNewLocalAliasLocalPart(action) RoomAliasAction.AddLocalAlias -> handleAddLocalAlias() is RoomAliasAction.RemoveLocalAlias -> handleRemoveLocalAlias(action) - is RoomAliasAction.PublishAlias -> handleAddAliasManually(action) + is RoomAliasAction.PublishAlias -> handlePublishAlias(action) }.exhaustive } @@ -212,39 +212,45 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo val newAlias = (state.publishManuallyState as? RoomAliasViewState.AddAliasState.Editing)?.value ?: return@withState updateCanonicalAlias( canonicalAlias = state.canonicalAlias, - alternativeAliases = state.alternativeAliases + newAlias + alternativeAliases = state.alternativeAliases + newAlias, + closeForm = true ) } - private fun handleAddAliasManually(action: RoomAliasAction.PublishAlias) = withState { state -> + private fun handlePublishAlias(action: RoomAliasAction.PublishAlias) = withState { state -> updateCanonicalAlias( canonicalAlias = state.canonicalAlias, - alternativeAliases = state.alternativeAliases + action.alias + alternativeAliases = state.alternativeAliases + action.alias, + closeForm = false ) } private fun handleRemoveAlias(action: RoomAliasAction.UnpublishAlias) = withState { state -> updateCanonicalAlias( canonicalAlias = state.canonicalAlias, - alternativeAliases = state.alternativeAliases - action.alias - ) + alternativeAliases = state.alternativeAliases - action.alias, + closeForm = false ) } private fun handleSetCanonicalAlias(action: RoomAliasAction.SetCanonicalAlias) = withState { state -> updateCanonicalAlias( canonicalAlias = action.canonicalAlias, - alternativeAliases = state.alternativeAliases + alternativeAliases = state.alternativeAliases, + closeForm = false ) } - private fun updateCanonicalAlias(canonicalAlias: String?, alternativeAliases: List) { + private fun updateCanonicalAlias(canonicalAlias: String?, alternativeAliases: List, closeForm: Boolean) { postLoading(true) room.updateCanonicalAlias(canonicalAlias, alternativeAliases, object : MatrixCallback { override fun onSuccess(data: Unit) { setState { copy( isLoading = false, - publishManuallyState = RoomAliasViewState.AddAliasState.Closed + publishManuallyState = if (closeForm) RoomAliasViewState.AddAliasState.Closed else publishManuallyState, + // Local echo + canonicalAlias = canonicalAlias, + alternativeAliases = alternativeAliases ) } }