diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasController.kt index d3d8a7bed7..56f3cb77c5 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasController.kt @@ -51,7 +51,7 @@ class RoomAliasController @Inject constructor( fun toggleLocalAliasForm() fun setNewLocalAliasLocalPart(value: String) fun addLocalAlias() - fun openAliasDetail(alias: String, isPublished: Boolean) + fun openAliasDetail(alias: String) } var callback: Callback? = null @@ -86,7 +86,7 @@ class RoomAliasController @Inject constructor( id("canonical") title(data.canonicalAlias) subtitle(stringProvider.getString(R.string.room_alias_published_alias_main)) - listener { callback?.openAliasDetail(canonicalAlias, true) } + listener { callback?.openAliasDetail(canonicalAlias) } } } @@ -108,7 +108,7 @@ class RoomAliasController @Inject constructor( profileActionItem { id("alt_$idx") title(altAlias) - listener { callback?.openAliasDetail(altAlias, true) } + listener { callback?.openAliasDetail(altAlias) } } } } @@ -169,7 +169,7 @@ class RoomAliasController @Inject constructor( profileActionItem { id("loc_$idx") title(localAlias) - listener { callback?.openAliasDetail(localAlias, false) } + listener { callback?.openAliasDetail(localAlias) } } } } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt index 9d3b7feda6..dd02691259 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasFragment.kt @@ -162,12 +162,13 @@ class RoomAliasFragment @Inject constructor( viewModel.handle(RoomAliasAction.AddLocalAlias) } - override fun openAliasDetail(alias: String, isPublished: Boolean) = withState(viewModel) { state -> + override fun openAliasDetail(alias: String) = withState(viewModel) { state -> RoomAliasBottomSheet .newInstance( alias = alias, - isPublished = isPublished, + isPublished = alias in state.allPublishedAliases, isMainAlias = alias == state.canonicalAlias, + isLocal = alias in state.localAliases().orEmpty(), canEditCanonicalAlias = state.actionPermissions.canChangeCanonicalAlias ) .show(childFragmentManager, "ROOM_ALIAS_ACTIONS") 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 8cfd589bb3..4aed4a55bb 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 @@ -236,7 +236,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo updateCanonicalAlias( canonicalAlias = action.canonicalAlias, // Ensure the previous canonical alias is moved to the alt aliases - alternativeAliases = (state.alternativeAliases + listOfNotNull(state.canonicalAlias)).distinct(), + alternativeAliases = state.allPublishedAliases, closeForm = false ) } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewState.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewState.kt index e1736296c6..cffff2ec4f 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewState.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/RoomAliasViewState.kt @@ -37,6 +37,9 @@ data class RoomAliasViewState( constructor(args: RoomProfileArgs) : this(roomId = args.roomId) + val allPublishedAliases: List + get() = (alternativeAliases + listOfNotNull(canonicalAlias)).distinct() + data class ActionPermissions( val canChangeCanonicalAlias: Boolean = false ) diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheet.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheet.kt index f9968d86da..86702d1507 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheet.kt @@ -36,6 +36,7 @@ data class RoomAliasBottomSheetArgs( val alias: String, val isPublished: Boolean, val isMainAlias: Boolean, + val isLocal: Boolean, val canEditCanonicalAlias: Boolean ) : Parcelable @@ -90,12 +91,14 @@ class RoomAliasBottomSheet : VectorBaseBottomSheetDialogFragment(), RoomAliasBot fun newInstance(alias: String, isPublished: Boolean, isMainAlias: Boolean, + isLocal: Boolean, canEditCanonicalAlias: Boolean): RoomAliasBottomSheet { return RoomAliasBottomSheet().apply { setArguments(RoomAliasBottomSheetArgs( alias = alias, isPublished = isPublished, isMainAlias = isMainAlias, + isLocal = isLocal, canEditCanonicalAlias = canEditCanonicalAlias )) } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheetController.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheetController.kt index 56a93d1527..157037c13d 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheetController.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheetController.kt @@ -59,9 +59,11 @@ class RoomAliasBottomSheetController @Inject constructor() : TypedEpoxyControlle } RoomAliasBottomSheetSharedAction.UnPublishAlias(state.alias).toBottomSheetItem(++idx) } - } else { + } + + if (state.isLocal) { // Local address - if (state.canEditCanonicalAlias) { + if (state.canEditCanonicalAlias && state.isPublished.not()) { // Publish RoomAliasBottomSheetSharedAction.PublishAlias(state.alias).toBottomSheetItem(++idx) } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheetState.kt b/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheetState.kt index 97ffcdf30c..a61075cef6 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheetState.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/alias/detail/RoomAliasBottomSheetState.kt @@ -23,6 +23,7 @@ data class RoomAliasBottomSheetState( val matrixToLink: String? = null, val isPublished: Boolean, val isMainAlias: Boolean, + val isLocal: Boolean, val canEditCanonicalAlias: Boolean ) : MvRxState { @@ -30,6 +31,7 @@ data class RoomAliasBottomSheetState( alias = args.alias, isPublished = args.isPublished, isMainAlias = args.isMainAlias, + isLocal = args.isLocal, canEditCanonicalAlias = args.canEditCanonicalAlias ) } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index 6e55567428..d9df53d99f 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -1034,7 +1034,7 @@ This is the main address Main address Other published addresses: - Published a new address manually + Publish a new address manually Publish Unpublish the address \"%1$s\"? Delete the address \"%1$s\"?