Add published aliases

This commit is contained in:
Benoit Marty 2020-11-23 17:38:38 +01:00 committed by Benoit Marty
parent 93580c902f
commit 3c069f8b79
6 changed files with 71 additions and 29 deletions

View file

@ -20,10 +20,10 @@ import im.vector.app.core.platform.VectorViewModelAction
sealed class RoomAliasAction : VectorViewModelAction {
// Canonical
data class AddAlias(val alias: String) : RoomAliasAction()
data class SetNewAlias(val aliasLocalPart: String) : RoomAliasAction()
object AddAlias : RoomAliasAction()
data class RemoveAlias(val alias: String) : RoomAliasAction()
data class SetCanonicalAlias(val canonicalAlias: String) : RoomAliasAction()
object UnSetCanonicalAlias : RoomAliasAction()
data class SetCanonicalAlias(val canonicalAlias: String?) : RoomAliasAction()
// Local
data class RemoveLocalAlias(val alias: String) : RoomAliasAction()

View file

@ -27,6 +27,7 @@ import im.vector.app.core.epoxy.profiles.buildProfileSection
import im.vector.app.core.error.ErrorFormatter
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.discovery.settingsInfoItem
import im.vector.app.features.form.formEditTextItem
import im.vector.app.features.form.formSubmitButtonItem
import im.vector.app.features.roomdirectory.createroom.RoomAliasErrorFormatter
import im.vector.app.features.roomdirectory.createroom.roomAliasEditItem
@ -41,9 +42,10 @@ class RoomAliasController @Inject constructor(
) : TypedEpoxyController<RoomAliasViewState>() {
interface Callback {
fun setNewAlias(value: String)
fun addAlias()
fun removeAlias(altAlias: String)
fun setCanonicalAlias(alias: String)
fun unsetCanonicalAlias()
fun setCanonicalAlias(alias: String?)
fun removeLocalAlias(alias: String)
fun setNewLocalAliasLocalPart(value: String)
fun addLocalAlias()
@ -67,16 +69,44 @@ class RoomAliasController @Inject constructor(
}
// TODO Canonical
if (data.alternativeAliases.isNotEmpty()) {
settingsInfoItem {
id("otherPublished")
helperTextResId(R.string.room_alias_published_other)
}
if (data.alternativeAliases.isEmpty()) {
settingsInfoItem {
id("otherPublished")
helperTextResId(R.string.room_alias_published_other)
id("otherPublishedEmpty")
if (data.actionPermissions.canChangeCanonicalAlias) {
helperTextResId(R.string.room_alias_address_empty_can_add)
} else {
helperTextResId(R.string.room_alias_address_empty)
}
}
data.alternativeAliases.forEachIndexed { idx, altAlias ->
// TODO Rename this item to a more generic name
threePidItem {
id("alt_$idx")
title(altAlias)
}
if (data.actionPermissions.canChangeCanonicalAlias) {
formEditTextItem {
id("addAlias")
value(data.newAlias)
showBottomSeparator(false)
hint(stringProvider.getString(R.string.room_alias_address_hint))
onTextChange { text ->
callback?.setNewAlias(text)
}
}
formSubmitButtonItem {
id("submit")
buttonTitleId(R.string.action_add)
buttonClickListener { callback?.addAlias() }
}
}
data.alternativeAliases.forEachIndexed { idx, altAlias ->
// TODO Rename this item to a more generic name
threePidItem {
id("alt_$idx")
title(altAlias)
if (data.actionPermissions.canChangeCanonicalAlias) {
deleteClickListener { callback?.removeAlias(altAlias) }
}
}
@ -132,7 +162,7 @@ class RoomAliasController @Inject constructor(
}
formSubmitButtonItem {
id("submit")
id("submitLocal")
buttonTitleId(R.string.action_add)
buttonClickListener { callback?.addLocalAlias() }
}

View file

@ -112,12 +112,16 @@ class RoomAliasFragment @Inject constructor(
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
}
override fun setCanonicalAlias(alias: String) {
override fun setCanonicalAlias(alias: String?) {
viewModel.handle(RoomAliasAction.SetCanonicalAlias(alias))
}
override fun unsetCanonicalAlias() {
viewModel.handle(RoomAliasAction.UnSetCanonicalAlias)
override fun setNewAlias(value: String) {
viewModel.handle(RoomAliasAction.SetNewAlias(value))
}
override fun addAlias() {
viewModel.handle(RoomAliasAction.AddAlias)
}
override fun setNewLocalAliasLocalPart(value: String) {

View file

@ -142,16 +142,25 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
override fun handle(action: RoomAliasAction) {
when (action) {
is RoomAliasAction.SetNewAlias -> handleSetNewAlias(action)
is RoomAliasAction.AddAlias -> handleAddAlias()
is RoomAliasAction.RemoveAlias -> handleRemoveAlias(action)
is RoomAliasAction.SetCanonicalAlias -> handleSetCanonicalAlias(action)
RoomAliasAction.UnSetCanonicalAlias -> handleUnsetCanonicalAlias()
is RoomAliasAction.SetNewLocalAliasLocalPart -> handleSetNewLocalAliasLocalPart(action)
RoomAliasAction.AddLocalAlias -> handleAddLocalAlias()
is RoomAliasAction.RemoveLocalAlias -> handleRemoveLocalAlias(action)
}.exhaustive
}
private fun handleSetNewAlias(action: RoomAliasAction.SetNewAlias) {
setState {
copy(
newAlias = action.aliasLocalPart,
asyncNewAliasRequest = Uninitialized
)
}
}
private fun handleSetNewLocalAliasLocalPart(action: RoomAliasAction.SetNewLocalAliasLocalPart) {
setState {
copy(
@ -162,7 +171,10 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
}
private fun handleAddAlias() = withState { state ->
TODO()
updateCanonicalAlias(
state.canonicalAlias,
state.alternativeAliases + state.newAlias
)
}
private fun handleRemoveAlias(action: RoomAliasAction.RemoveAlias) = withState { state ->
@ -179,13 +191,6 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
)
}
private fun handleUnsetCanonicalAlias() = withState { state ->
updateCanonicalAlias(
null,
state.alternativeAliases
)
}
private fun updateCanonicalAlias(canonicalAlias: String?, alternativeAliases: List<String>) {
postLoading(true)
room.updateCanonicalAlias(canonicalAlias, alternativeAliases, object : MatrixCallback<Unit> {

View file

@ -26,13 +26,15 @@ data class RoomAliasViewState(
val roomId: String,
val homeServerName: String = "",
val roomSummary: Async<RoomSummary> = Uninitialized,
val actionPermissions: ActionPermissions = ActionPermissions(),
val isLoading: Boolean = false,
val canonicalAlias: String? = null,
val alternativeAliases: List<String> = emptyList(),
val newAlias: String = "",
val asyncNewAliasRequest: Async<Unit> = Uninitialized,
val localAliases: Async<List<String>> = Uninitialized,
val newLocalAlias: String = "",
val asyncNewLocalAliasRequest: Async<Unit> = Uninitialized,
val actionPermissions: ActionPermissions = ActionPermissions()
val asyncNewLocalAliasRequest: Async<Unit> = Uninitialized
) : MvRxState {
constructor(args: RoomProfileArgs) : this(roomId = args.roomId)

View file

@ -1035,7 +1035,8 @@
<string name="room_alias_delete_confirmation">Delete the address \"%1$s\"?</string>
<!-- Parameter will be the url of the homeserver, ex: matrix.org -->
<string name="room_alias_publish">Publish this room to the public in %1$s\'s room directory?</string>
<string name="room_alias_address_empty">No other published addresses yet, add one below</string>
<string name="room_alias_address_empty_can_add">No other published addresses yet, add one below.</string>
<string name="room_alias_address_empty">No other published addresses yet.</string>
<string name="room_alias_address_hint">New published address (e.g. #alias:server)</string>
<string name="room_alias_local_address_title">Local Addresses</string>