Do check only on Debug

This commit is contained in:
Benoit Marty
2023-04-13 13:00:16 +02:00
parent 1f7b897216
commit 798629faf7
6 changed files with 18 additions and 42 deletions

View File

@@ -22,12 +22,8 @@ import java.io.Serializable
@JvmInline
value class EventId(val value: String) : Serializable
fun String.asEventId() = if (MatrixPatterns.isEventId(this)) {
EventId(this)
fun String.asEventId() = if (BuildConfig.DEBUG && !MatrixPatterns.isEventId(this)) {
error("`$this` is not a valid event Id")
} else {
if (BuildConfig.DEBUG) {
error("`$this` is not a valid event Id")
} else {
null
}
EventId(this)
}

View File

@@ -22,12 +22,8 @@ import java.io.Serializable
@JvmInline
value class RoomId(val value: String) : Serializable
fun String.asRoomId() = if (MatrixPatterns.isRoomId(this)) {
RoomId(this)
fun String.asRoomId() = if (BuildConfig.DEBUG && !MatrixPatterns.isRoomId(this)) {
error("`$this` is not a valid room Id")
} else {
if (BuildConfig.DEBUG) {
error("`$this` is not a valid room Id")
} else {
null
}
RoomId(this)
}

View File

@@ -20,12 +20,8 @@ import io.element.android.libraries.matrix.api.BuildConfig
typealias SessionId = UserId
fun String.asSessionId() = if (MatrixPatterns.isSessionId(this)) {
SessionId(this)
fun String.asSessionId() = if (BuildConfig.DEBUG && !MatrixPatterns.isSessionId(this)) {
error("`$this` is not a valid session Id")
} else {
if (BuildConfig.DEBUG) {
error("`$this` is not a valid session Id")
} else {
null
}
SessionId(this)
}

View File

@@ -27,12 +27,8 @@ value class SpaceId(val value: String) : Serializable
*/
val MAIN_SPACE = SpaceId("!mainSpace")
fun String.asSpaceId() = if (MatrixPatterns.isSpaceId(this)) {
SpaceId(this)
fun String.asSpaceId() = if (BuildConfig.DEBUG && !MatrixPatterns.isSpaceId(this)) {
error("`$this` is not a valid space Id")
} else {
if (BuildConfig.DEBUG) {
error("`$this` is not a valid space Id")
} else {
null
}
SpaceId(this)
}

View File

@@ -22,12 +22,8 @@ import java.io.Serializable
@JvmInline
value class ThreadId(val value: String) : Serializable
fun String.asThreadId() = if (MatrixPatterns.isThreadId(this)) {
ThreadId(this)
fun String.asThreadId() = if (BuildConfig.DEBUG && !MatrixPatterns.isThreadId(this)) {
error("`$this` is not a valid thread Id")
} else {
if (BuildConfig.DEBUG) {
error("`$this` is not a valid thread Id")
} else {
null
}
ThreadId(this)
}

View File

@@ -22,12 +22,8 @@ import java.io.Serializable
@JvmInline
value class UserId(val value: String) : Serializable
fun String.asUserId() = if (MatrixPatterns.isUserId(this)) {
UserId(this)
fun String.asUserId() = if (BuildConfig.DEBUG && !MatrixPatterns.isUserId(this)) {
error("`$this` is not a valid user Id")
} else {
if (BuildConfig.DEBUG) {
error("`$this` is not a valid user Id")
} else {
null
}
UserId(this)
}