Do not rely on RoomAlias constructor to validate the Room alias, since there is no validation in release mode.
This is fixing the test in release mode.
This commit is contained in:
parent
39b51b4904
commit
070fd4f53a
3 changed files with 10 additions and 7 deletions
|
|
@ -99,7 +99,7 @@ class EditRoomAddressPresenter @AssistedInject constructor(
|
|||
suspend {
|
||||
val savedCanonicalAlias = room.canonicalAlias
|
||||
val savedAliasFromHomeserver = room.firstAliasMatching(serverName)
|
||||
val newRoomAlias = client.roomAliasFromName(newRoomAddress).getOrThrow()
|
||||
val newRoomAlias = client.roomAliasFromName(newRoomAddress) ?: throw IllegalArgumentException("Invalid room address")
|
||||
|
||||
// First publish the new alias in the room directory
|
||||
room.publishRoomAliasInRoomDirectory(newRoomAlias).getOrThrow()
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api
|
||||
|
||||
import io.element.android.libraries.core.data.tryOrNull
|
||||
import io.element.android.libraries.matrix.api.core.DeviceId
|
||||
import io.element.android.libraries.matrix.api.core.MatrixPatterns
|
||||
import io.element.android.libraries.matrix.api.core.ProgressCallback
|
||||
import io.element.android.libraries.matrix.api.core.RoomAlias
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
|
|
@ -172,11 +174,12 @@ fun MatrixClient.getRoomInfoFlow(roomIdOrAlias: RoomIdOrAlias): Flow<Optional<Ma
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a room alias from a room alias name.
|
||||
* Returns a room alias from a room alias name, or null if the name is not valid.
|
||||
* @param name the room alias name ie. the local part of the room alias.
|
||||
*/
|
||||
fun MatrixClient.roomAliasFromName(name: String): Result<RoomAlias> {
|
||||
return runCatching {
|
||||
RoomAlias("#$name:${userIdServerName()}")
|
||||
}
|
||||
fun MatrixClient.roomAliasFromName(name: String): RoomAlias? {
|
||||
return name.takeIf { it.isNotEmpty() }
|
||||
?.let { "#$it:${userIdServerName()}" }
|
||||
?.takeIf { MatrixPatterns.isRoomAlias(it) }
|
||||
?.let { tryOrNull { RoomAlias(it) } }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ fun RoomAddressValidityEffect(
|
|||
}
|
||||
// debounce the room address validation
|
||||
delay(300)
|
||||
val roomAlias = client.roomAliasFromName(newRoomAddress).getOrNull()
|
||||
val roomAlias = client.roomAliasFromName(newRoomAddress)
|
||||
if (roomAlias == null || !roomAliasHelper.isRoomAliasValid(roomAlias)) {
|
||||
onChange(RoomAddressValidity.InvalidSymbols)
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue