mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 19:36:08 +03:00
Add published aliases
This commit is contained in:
parent
93580c902f
commit
3c069f8b79
6 changed files with 71 additions and 29 deletions
|
@ -20,10 +20,10 @@ import im.vector.app.core.platform.VectorViewModelAction
|
||||||
|
|
||||||
sealed class RoomAliasAction : VectorViewModelAction {
|
sealed class RoomAliasAction : VectorViewModelAction {
|
||||||
// Canonical
|
// 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 RemoveAlias(val alias: String) : RoomAliasAction()
|
||||||
data class SetCanonicalAlias(val canonicalAlias: String) : RoomAliasAction()
|
data class SetCanonicalAlias(val canonicalAlias: String?) : RoomAliasAction()
|
||||||
object UnSetCanonicalAlias : RoomAliasAction()
|
|
||||||
|
|
||||||
// Local
|
// Local
|
||||||
data class RemoveLocalAlias(val alias: String) : RoomAliasAction()
|
data class RemoveLocalAlias(val alias: String) : RoomAliasAction()
|
||||||
|
|
|
@ -27,6 +27,7 @@ import im.vector.app.core.epoxy.profiles.buildProfileSection
|
||||||
import im.vector.app.core.error.ErrorFormatter
|
import im.vector.app.core.error.ErrorFormatter
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.features.discovery.settingsInfoItem
|
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.form.formSubmitButtonItem
|
||||||
import im.vector.app.features.roomdirectory.createroom.RoomAliasErrorFormatter
|
import im.vector.app.features.roomdirectory.createroom.RoomAliasErrorFormatter
|
||||||
import im.vector.app.features.roomdirectory.createroom.roomAliasEditItem
|
import im.vector.app.features.roomdirectory.createroom.roomAliasEditItem
|
||||||
|
@ -41,9 +42,10 @@ class RoomAliasController @Inject constructor(
|
||||||
) : TypedEpoxyController<RoomAliasViewState>() {
|
) : TypedEpoxyController<RoomAliasViewState>() {
|
||||||
|
|
||||||
interface Callback {
|
interface Callback {
|
||||||
|
fun setNewAlias(value: String)
|
||||||
|
fun addAlias()
|
||||||
fun removeAlias(altAlias: String)
|
fun removeAlias(altAlias: String)
|
||||||
fun setCanonicalAlias(alias: String)
|
fun setCanonicalAlias(alias: String?)
|
||||||
fun unsetCanonicalAlias()
|
|
||||||
fun removeLocalAlias(alias: String)
|
fun removeLocalAlias(alias: String)
|
||||||
fun setNewLocalAliasLocalPart(value: String)
|
fun setNewLocalAliasLocalPart(value: String)
|
||||||
fun addLocalAlias()
|
fun addLocalAlias()
|
||||||
|
@ -67,16 +69,44 @@ class RoomAliasController @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Canonical
|
// TODO Canonical
|
||||||
if (data.alternativeAliases.isNotEmpty()) {
|
settingsInfoItem {
|
||||||
|
id("otherPublished")
|
||||||
|
helperTextResId(R.string.room_alias_published_other)
|
||||||
|
}
|
||||||
|
if (data.alternativeAliases.isEmpty()) {
|
||||||
settingsInfoItem {
|
settingsInfoItem {
|
||||||
id("otherPublished")
|
id("otherPublishedEmpty")
|
||||||
helperTextResId(R.string.room_alias_published_other)
|
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 {
|
if (data.actionPermissions.canChangeCanonicalAlias) {
|
||||||
id("alt_$idx")
|
formEditTextItem {
|
||||||
title(altAlias)
|
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) }
|
deleteClickListener { callback?.removeAlias(altAlias) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +162,7 @@ class RoomAliasController @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
formSubmitButtonItem {
|
formSubmitButtonItem {
|
||||||
id("submit")
|
id("submitLocal")
|
||||||
buttonTitleId(R.string.action_add)
|
buttonTitleId(R.string.action_add)
|
||||||
buttonClickListener { callback?.addLocalAlias() }
|
buttonClickListener { callback?.addLocalAlias() }
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,12 +112,16 @@ class RoomAliasFragment @Inject constructor(
|
||||||
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
|
.withColoredButton(DialogInterface.BUTTON_POSITIVE)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setCanonicalAlias(alias: String) {
|
override fun setCanonicalAlias(alias: String?) {
|
||||||
viewModel.handle(RoomAliasAction.SetCanonicalAlias(alias))
|
viewModel.handle(RoomAliasAction.SetCanonicalAlias(alias))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unsetCanonicalAlias() {
|
override fun setNewAlias(value: String) {
|
||||||
viewModel.handle(RoomAliasAction.UnSetCanonicalAlias)
|
viewModel.handle(RoomAliasAction.SetNewAlias(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addAlias() {
|
||||||
|
viewModel.handle(RoomAliasAction.AddAlias)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setNewLocalAliasLocalPart(value: String) {
|
override fun setNewLocalAliasLocalPart(value: String) {
|
||||||
|
|
|
@ -142,16 +142,25 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
|
||||||
|
|
||||||
override fun handle(action: RoomAliasAction) {
|
override fun handle(action: RoomAliasAction) {
|
||||||
when (action) {
|
when (action) {
|
||||||
|
is RoomAliasAction.SetNewAlias -> handleSetNewAlias(action)
|
||||||
is RoomAliasAction.AddAlias -> handleAddAlias()
|
is RoomAliasAction.AddAlias -> handleAddAlias()
|
||||||
is RoomAliasAction.RemoveAlias -> handleRemoveAlias(action)
|
is RoomAliasAction.RemoveAlias -> handleRemoveAlias(action)
|
||||||
is RoomAliasAction.SetCanonicalAlias -> handleSetCanonicalAlias(action)
|
is RoomAliasAction.SetCanonicalAlias -> handleSetCanonicalAlias(action)
|
||||||
RoomAliasAction.UnSetCanonicalAlias -> handleUnsetCanonicalAlias()
|
|
||||||
is RoomAliasAction.SetNewLocalAliasLocalPart -> handleSetNewLocalAliasLocalPart(action)
|
is RoomAliasAction.SetNewLocalAliasLocalPart -> handleSetNewLocalAliasLocalPart(action)
|
||||||
RoomAliasAction.AddLocalAlias -> handleAddLocalAlias()
|
RoomAliasAction.AddLocalAlias -> handleAddLocalAlias()
|
||||||
is RoomAliasAction.RemoveLocalAlias -> handleRemoveLocalAlias(action)
|
is RoomAliasAction.RemoveLocalAlias -> handleRemoveLocalAlias(action)
|
||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleSetNewAlias(action: RoomAliasAction.SetNewAlias) {
|
||||||
|
setState {
|
||||||
|
copy(
|
||||||
|
newAlias = action.aliasLocalPart,
|
||||||
|
asyncNewAliasRequest = Uninitialized
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleSetNewLocalAliasLocalPart(action: RoomAliasAction.SetNewLocalAliasLocalPart) {
|
private fun handleSetNewLocalAliasLocalPart(action: RoomAliasAction.SetNewLocalAliasLocalPart) {
|
||||||
setState {
|
setState {
|
||||||
copy(
|
copy(
|
||||||
|
@ -162,7 +171,10 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleAddAlias() = withState { state ->
|
private fun handleAddAlias() = withState { state ->
|
||||||
TODO()
|
updateCanonicalAlias(
|
||||||
|
state.canonicalAlias,
|
||||||
|
state.alternativeAliases + state.newAlias
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRemoveAlias(action: RoomAliasAction.RemoveAlias) = withState { state ->
|
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>) {
|
private fun updateCanonicalAlias(canonicalAlias: String?, alternativeAliases: List<String>) {
|
||||||
postLoading(true)
|
postLoading(true)
|
||||||
room.updateCanonicalAlias(canonicalAlias, alternativeAliases, object : MatrixCallback<Unit> {
|
room.updateCanonicalAlias(canonicalAlias, alternativeAliases, object : MatrixCallback<Unit> {
|
||||||
|
|
|
@ -26,13 +26,15 @@ data class RoomAliasViewState(
|
||||||
val roomId: String,
|
val roomId: String,
|
||||||
val homeServerName: String = "",
|
val homeServerName: String = "",
|
||||||
val roomSummary: Async<RoomSummary> = Uninitialized,
|
val roomSummary: Async<RoomSummary> = Uninitialized,
|
||||||
|
val actionPermissions: ActionPermissions = ActionPermissions(),
|
||||||
val isLoading: Boolean = false,
|
val isLoading: Boolean = false,
|
||||||
val canonicalAlias: String? = null,
|
val canonicalAlias: String? = null,
|
||||||
val alternativeAliases: List<String> = emptyList(),
|
val alternativeAliases: List<String> = emptyList(),
|
||||||
|
val newAlias: String = "",
|
||||||
|
val asyncNewAliasRequest: Async<Unit> = Uninitialized,
|
||||||
val localAliases: Async<List<String>> = Uninitialized,
|
val localAliases: Async<List<String>> = Uninitialized,
|
||||||
val newLocalAlias: String = "",
|
val newLocalAlias: String = "",
|
||||||
val asyncNewLocalAliasRequest: Async<Unit> = Uninitialized,
|
val asyncNewLocalAliasRequest: Async<Unit> = Uninitialized
|
||||||
val actionPermissions: ActionPermissions = ActionPermissions()
|
|
||||||
) : MvRxState {
|
) : MvRxState {
|
||||||
|
|
||||||
constructor(args: RoomProfileArgs) : this(roomId = args.roomId)
|
constructor(args: RoomProfileArgs) : this(roomId = args.roomId)
|
||||||
|
|
|
@ -1035,7 +1035,8 @@
|
||||||
<string name="room_alias_delete_confirmation">Delete the address \"%1$s\"?</string>
|
<string name="room_alias_delete_confirmation">Delete the address \"%1$s\"?</string>
|
||||||
<!-- Parameter will be the url of the homeserver, ex: matrix.org -->
|
<!-- 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_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_address_hint">New published address (e.g. #alias:server)</string>
|
||||||
|
|
||||||
<string name="room_alias_local_address_title">Local Addresses</string>
|
<string name="room_alias_local_address_title">Local Addresses</string>
|
||||||
|
|
Loading…
Reference in a new issue