Introduce value class RoomAlias
This commit is contained in:
parent
2a467bd49b
commit
bd12ff737b
8 changed files with 50 additions and 12 deletions
|
|
@ -17,6 +17,7 @@
|
|||
package io.element.android.libraries.matrix.api
|
||||
|
||||
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
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
|
|
@ -99,6 +100,6 @@ interface MatrixClient : Closeable {
|
|||
|
||||
suspend fun trackRecentlyVisitedRoom(roomId: RoomId): Result<Unit>
|
||||
suspend fun getRecentlyVisitedRooms(): Result<List<RoomId>>
|
||||
suspend fun resolveRoomAlias(roomAlias: String): Result<RoomId>
|
||||
suspend fun resolveRoomAlias(roomAlias: RoomAlias): Result<RoomId>
|
||||
suspend fun getRoomPreview(roomIdOrAlias: String): Result<RoomPreview>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2024 New Vector Ltd
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.api.core
|
||||
|
||||
import io.element.android.libraries.androidutils.metadata.isInDebug
|
||||
import java.io.Serializable
|
||||
|
||||
@JvmInline
|
||||
value class RoomAlias(val value: String) : Serializable {
|
||||
init {
|
||||
if (isInDebug && !MatrixPatterns.isRoomAlias(value)) {
|
||||
error("`$value` is not a valid room alias.\n Example room alias: `#room_alias:domain`.")
|
||||
}
|
||||
}
|
||||
|
||||
override fun toString(): String = value
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ package io.element.android.libraries.matrix.api.permalink
|
|||
import android.net.Uri
|
||||
import androidx.compose.runtime.Immutable
|
||||
import io.element.android.libraries.matrix.api.core.EventId
|
||||
import io.element.android.libraries.matrix.api.core.RoomAlias
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
|
@ -39,7 +40,7 @@ sealed interface PermalinkData {
|
|||
) : RoomLink
|
||||
|
||||
data class RoomAliasLink(
|
||||
val roomAlias: String,
|
||||
val roomAlias: RoomAlias,
|
||||
override val viaParameters: ImmutableList<String>
|
||||
) : RoomLink
|
||||
|
||||
|
|
@ -55,7 +56,7 @@ sealed interface PermalinkData {
|
|||
) : EventLink
|
||||
|
||||
data class EventIdAliasLink(
|
||||
val roomAlias: String,
|
||||
val roomAlias: RoomAlias,
|
||||
override val eventId: EventId,
|
||||
override val viaParameters: ImmutableList<String>
|
||||
) : EventLink
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue