Cleanup and avoid duplicate

This commit is contained in:
Benoit Marty 2020-11-23 17:59:25 +01:00 committed by Benoit Marty
parent 893ebd9690
commit ed4676bb6c
3 changed files with 15 additions and 11 deletions

View file

@ -111,7 +111,7 @@ internal class DefaultStateService @AssistedInject constructor(@Assisted private
eventType = EventType.STATE_ROOM_CANONICAL_ALIAS,
body = RoomCanonicalAliasContent(
canonicalAlias = alias,
alternativeAliases = altAliases
alternativeAliases = altAliases.distinct()
).toContent(),
callback = callback,
stateKey = null

View file

@ -142,21 +142,20 @@ 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)
is RoomAliasAction.SetNewAlias -> handleSetNewAlias(action)
is RoomAliasAction.AddAlias -> handleAddAlias()
is RoomAliasAction.RemoveAlias -> handleRemoveAlias(action)
is RoomAliasAction.SetCanonicalAlias -> handleSetCanonicalAlias(action)
is RoomAliasAction.SetNewLocalAliasLocalPart -> handleSetNewLocalAliasLocalPart(action)
RoomAliasAction.AddLocalAlias -> handleAddLocalAlias()
is RoomAliasAction.RemoveLocalAlias -> handleRemoveLocalAlias(action)
RoomAliasAction.AddLocalAlias -> handleAddLocalAlias()
is RoomAliasAction.RemoveLocalAlias -> handleRemoveLocalAlias(action)
}.exhaustive
}
private fun handleSetNewAlias(action: RoomAliasAction.SetNewAlias) {
setState {
copy(
newAlias = action.aliasLocalPart,
asyncNewAliasRequest = Uninitialized
newAlias = action.aliasLocalPart
)
}
}
@ -195,7 +194,12 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
postLoading(true)
room.updateCanonicalAlias(canonicalAlias, alternativeAliases, object : MatrixCallback<Unit> {
override fun onSuccess(data: Unit) {
postLoading(false)
setState {
copy(
isLoading = false,
newAlias = ""
)
}
}
override fun onFailure(failure: Throwable) {
@ -228,6 +232,7 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
setState {
copy(
isLoading = false,
newLocalAlias = "",
asyncNewLocalAliasRequest = Uninitialized
)
}

View file

@ -31,7 +31,6 @@ data class RoomAliasViewState(
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