Small cleanup, handle case of no local alias, handle unpublish of canonical alias

This commit is contained in:
Benoit Marty 2020-11-24 16:14:38 +01:00 committed by Benoit Marty
parent 6c7eb6ea8c
commit 50ddd3cf31
4 changed files with 17 additions and 8 deletions

View file

@ -320,7 +320,8 @@ internal interface RoomAPI {
@Body body: ReportContentBody): Call<Unit>
/**
* Get local aliases of this room
* Get a list of aliases maintained by the local server for the given room.
* Ref: https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-rooms-roomid-aliases
*/
@GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "org.matrix.msc2432/rooms/{roomId}/aliases")
fun getAliases(@Path("roomId") roomId: String): Call<GetAliasesResponse>

View file

@ -22,7 +22,7 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
internal data class GetAliasesResponse(
/**
* The list of aliases currently defined on the local server for the given room
* Required. The server's local aliases on the room. Can be empty.
*/
@Json(name = "aliases") val aliases: List<String> = emptyList()
)

View file

@ -199,11 +199,18 @@ class RoomAliasController @Inject constructor(
}
}
is Success -> {
localAliases().forEachIndexed { idx, localAlias ->
profileActionItem {
id("loc_$idx")
title(localAlias)
listener { callback?.openAliasDetail(localAlias) }
if (localAliases().isEmpty()) {
settingsInfoItem {
id("locEmpty")
helperTextResId(R.string.room_alias_local_address_empty)
}
} else {
localAliases().forEachIndexed { idx, localAlias ->
profileActionItem {
id("loc_$idx")
title(localAlias)
listener { callback?.openAliasDetail(localAlias) }
}
}
}
}

View file

@ -283,7 +283,8 @@ class RoomAliasViewModel @AssistedInject constructor(@Assisted initialState: Roo
private fun handleUnpublishAlias(action: RoomAliasAction.UnpublishAlias) = withState { state ->
updateCanonicalAlias(
canonicalAlias = state.canonicalAlias,
// We can also unpublish the canonical alias
canonicalAlias = state.canonicalAlias.takeIf { it != action.alias },
alternativeAliases = state.alternativeAliases - action.alias,
closeForm = false
)