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,6 +199,12 @@ class RoomAliasController @Inject constructor(
} }
} }
is Success -> { is Success -> {
if (localAliases().isEmpty()) {
settingsInfoItem {
id("locEmpty")
helperTextResId(R.string.room_alias_local_address_empty)
}
} else {
localAliases().forEachIndexed { idx, localAlias -> localAliases().forEachIndexed { idx, localAlias ->
profileActionItem { profileActionItem {
id("loc_$idx") id("loc_$idx")
@ -207,6 +213,7 @@ class RoomAliasController @Inject constructor(
} }
} }
} }
}
is Fail -> { is Fail -> {
errorWithRetryItem { errorWithRetryItem {
id("alt_error") id("alt_error")

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
) )