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> @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") @GET(NetworkConstants.URI_API_PREFIX_PATH_UNSTABLE + "org.matrix.msc2432/rooms/{roomId}/aliases")
fun getAliases(@Path("roomId") roomId: String): Call<GetAliasesResponse> fun getAliases(@Path("roomId") roomId: String): Call<GetAliasesResponse>

View file

@ -22,7 +22,7 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
internal data class GetAliasesResponse( 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() @Json(name = "aliases") val aliases: List<String> = emptyList()
) )

View file

@ -199,11 +199,18 @@ class RoomAliasController @Inject constructor(
} }
} }
is Success -> { is Success -> {
localAliases().forEachIndexed { idx, localAlias -> if (localAliases().isEmpty()) {
profileActionItem { settingsInfoItem {
id("loc_$idx") id("locEmpty")
title(localAlias) helperTextResId(R.string.room_alias_local_address_empty)
listener { callback?.openAliasDetail(localAlias) } }
} 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 -> private fun handleUnpublishAlias(action: RoomAliasAction.UnpublishAlias) = withState { state ->
updateCanonicalAlias( updateCanonicalAlias(
canonicalAlias = state.canonicalAlias, // We can also unpublish the canonical alias
canonicalAlias = state.canonicalAlias.takeIf { it != action.alias },
alternativeAliases = state.alternativeAliases - action.alias, alternativeAliases = state.alternativeAliases - action.alias,
closeForm = false closeForm = false
) )