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 6790bee2a8..d3d8a7bed7 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 openAlias(alias: String, isPublished: Boolean)
+ fun openAliasDetail(alias: String, isPublished: Boolean)
}
var callback: Callback? = null
@@ -78,7 +78,17 @@ class RoomAliasController @Inject constructor(
helperTextResId(R.string.room_alias_published_alias_subtitle)
}
- // TODO Set/Unset Canonical
+ data.canonicalAlias
+ ?.takeIf { it.isNotEmpty() }
+ ?.let { canonicalAlias ->
+
+ profileActionItem {
+ id("canonical")
+ title(data.canonicalAlias)
+ subtitle(stringProvider.getString(R.string.room_alias_published_alias_main))
+ listener { callback?.openAliasDetail(canonicalAlias, true) }
+ }
+ }
if (data.alternativeAliases.isEmpty()) {
settingsInfoItem {
@@ -98,7 +108,7 @@ class RoomAliasController @Inject constructor(
profileActionItem {
id("alt_$idx")
title(altAlias)
- listener { callback?.openAlias(altAlias, true) }
+ listener { callback?.openAliasDetail(altAlias, true) }
}
}
}
@@ -110,8 +120,8 @@ class RoomAliasController @Inject constructor(
private fun buildPublishManuallyForm(data: RoomAliasViewState) {
when (data.publishManuallyState) {
- RoomAliasViewState.AddAliasState.Hidden -> Unit
- RoomAliasViewState.AddAliasState.Closed -> {
+ RoomAliasViewState.AddAliasState.Hidden -> Unit
+ RoomAliasViewState.AddAliasState.Closed -> {
settingsButtonItem {
id("publishManually")
colorProvider(colorProvider)
@@ -154,16 +164,16 @@ class RoomAliasController @Inject constructor(
id("loadingAliases")
}
}
- is Success -> {
+ is Success -> {
localAliases().forEachIndexed { idx, localAlias ->
profileActionItem {
id("loc_$idx")
title(localAlias)
- listener { callback?.openAlias(localAlias, false) }
+ listener { callback?.openAliasDetail(localAlias, false) }
}
}
}
- is Fail -> {
+ is Fail -> {
errorWithRetryItem {
id("alt_error")
text(errorFormatter.toHumanReadable(localAliases.error))
@@ -177,8 +187,8 @@ class RoomAliasController @Inject constructor(
private fun buildAddLocalAlias(data: RoomAliasViewState) {
when (data.newLocalAliasState) {
- RoomAliasViewState.AddAliasState.Hidden -> Unit
- RoomAliasViewState.AddAliasState.Closed -> {
+ RoomAliasViewState.AddAliasState.Hidden -> Unit
+ RoomAliasViewState.AddAliasState.Closed -> {
settingsButtonItem {
id("newLocalAliasButton")
colorProvider(colorProvider)
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 f54cff5c6c..9d3b7feda6 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
@@ -113,29 +113,26 @@ class RoomAliasFragment @Inject constructor(
super.onDestroyView()
}
- override fun invalidate() = withState(viewModel) { viewState ->
- controller.setData(viewState)
- renderRoomSummary(viewState)
+ override fun invalidate() = withState(viewModel) { state ->
+ waiting_view.isVisible = state.isLoading
+ controller.setData(state)
+ renderRoomSummary(state)
}
private fun renderRoomSummary(state: RoomAliasViewState) {
- waiting_view.isVisible = state.isLoading
-
state.roomSummary()?.let {
roomSettingsToolbarTitleView.text = it.displayName
avatarRenderer.render(it.toMatrixItem(), roomSettingsToolbarAvatarImageView)
}
-
- invalidateOptionsMenu()
}
- private fun unpublishAlias(altAlias: String) {
+ private fun unpublishAlias(alias: String) {
AlertDialog.Builder(requireContext())
.setTitle(R.string.dialog_title_confirmation)
- .setMessage(getString(R.string.room_alias_delete_confirmation, altAlias))
+ .setMessage(getString(R.string.room_alias_unpublish_confirmation, alias))
.setNegativeButton(R.string.cancel, null)
- .setPositiveButton(R.string.delete) { _, _ ->
- viewModel.handle(RoomAliasAction.UnpublishAlias(altAlias))
+ .setPositiveButton(R.string.action_unpublish) { _, _ ->
+ viewModel.handle(RoomAliasAction.UnpublishAlias(alias))
}
.show()
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
@@ -165,7 +162,7 @@ class RoomAliasFragment @Inject constructor(
viewModel.handle(RoomAliasAction.AddLocalAlias)
}
- override fun openAlias(alias: String, isPublished: Boolean) = withState(viewModel) { state ->
+ override fun openAliasDetail(alias: String, isPublished: Boolean) = withState(viewModel) { state ->
RoomAliasBottomSheet
.newInstance(
alias = alias,
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 3110c22e21..8cfd589bb3 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
@@ -157,8 +157,8 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
when (action) {
RoomAliasAction.ToggleManualPublishForm -> handleToggleManualPublishForm()
is RoomAliasAction.SetNewAlias -> handleSetNewAlias(action)
- is RoomAliasAction.ManualPublishAlias -> handleAddAlias()
- is RoomAliasAction.UnpublishAlias -> handleRemoveAlias(action)
+ is RoomAliasAction.ManualPublishAlias -> handleManualPublishAlias()
+ is RoomAliasAction.UnpublishAlias -> handleUnpublishAlias(action)
is RoomAliasAction.SetCanonicalAlias -> handleSetCanonicalAlias(action)
RoomAliasAction.ToggleAddLocalAliasForm -> handleToggleAddLocalAliasForm()
is RoomAliasAction.SetNewLocalAliasLocalPart -> handleSetNewLocalAliasLocalPart(action)
@@ -208,7 +208,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
}
}
- private fun handleAddAlias() = withState { state ->
+ private fun handleManualPublishAlias() = withState { state ->
val newAlias = (state.publishManuallyState as? RoomAliasViewState.AddAliasState.Editing)?.value ?: return@withState
updateCanonicalAlias(
canonicalAlias = state.canonicalAlias,
@@ -225,7 +225,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
)
}
- private fun handleRemoveAlias(action: RoomAliasAction.UnpublishAlias) = withState { state ->
+ private fun handleUnpublishAlias(action: RoomAliasAction.UnpublishAlias) = withState { state ->
updateCanonicalAlias(
canonicalAlias = state.canonicalAlias,
alternativeAliases = state.alternativeAliases - action.alias,
@@ -235,7 +235,8 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
private fun handleSetCanonicalAlias(action: RoomAliasAction.SetCanonicalAlias) = withState { state ->
updateCanonicalAlias(
canonicalAlias = action.canonicalAlias,
- alternativeAliases = state.alternativeAliases,
+ // Ensure the previous canonical alias is moved to the alt aliases
+ alternativeAliases = (state.alternativeAliases + listOfNotNull(state.canonicalAlias)).distinct(),
closeForm = false
)
}
@@ -247,10 +248,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
setState {
copy(
isLoading = false,
- publishManuallyState = if (closeForm) RoomAliasViewState.AddAliasState.Closed else publishManuallyState,
- // Local echo
- canonicalAlias = canonicalAlias,
- alternativeAliases = alternativeAliases
+ publishManuallyState = if (closeForm) RoomAliasViewState.AddAliasState.Closed else publishManuallyState
)
}
}
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 2f4cb357b4..56a93d1527 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
@@ -34,6 +34,7 @@ class RoomAliasBottomSheetController @Inject constructor() : TypedEpoxyControlle
id("alias")
title(state.alias)
subtitle(state.matrixToLink)
+ editable(false)
}
// Notifications
diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml
index 327161233d..6e55567428 100644
--- a/vector/src/main/res/values/strings.xml
+++ b/vector/src/main/res/values/strings.xml
@@ -138,6 +138,7 @@
Close
Copy
Add
+ Unpublish
Copied to clipboard
Disable
@@ -1030,10 +1031,12 @@
Room Addresses
Published Addresses
Published addresses can be used by anyone on any server to join your room. To publish an address, it needs to be set as a local address first.
+ This is the main address
Main address
Other published addresses:
Published a new address manually
Publish
+ Unpublish the address \"%1$s\"?
Delete the address \"%1$s\"?
Publish this room to the public in %1$s\'s room directory?