Parse permalink using parseMatrixEntityFrom.
Create new PermalinkData type for link to Events. Keep matrixToConverter for now to first convert to matrix.to link. At some point it may be done by the SDK. Remove parse(Uri)
This commit is contained in:
parent
89d2f43b1a
commit
3df328b1ab
14 changed files with 125 additions and 241 deletions
|
|
@ -18,7 +18,9 @@ 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.RoomId
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
/**
|
||||
|
|
@ -27,28 +29,44 @@ import kotlinx.collections.immutable.ImmutableList
|
|||
*/
|
||||
@Immutable
|
||||
sealed interface PermalinkData {
|
||||
data class RoomLink(
|
||||
val roomIdOrAlias: String,
|
||||
val isRoomAlias: Boolean,
|
||||
val eventId: String?,
|
||||
sealed interface RoomLink : PermalinkData {
|
||||
val viaParameters: ImmutableList<String>
|
||||
) : PermalinkData {
|
||||
fun getRoomId(): RoomId? {
|
||||
return roomIdOrAlias.takeIf { !isRoomAlias }?.let(::RoomId)
|
||||
}
|
||||
|
||||
fun getRoomAlias(): String? {
|
||||
return roomIdOrAlias.takeIf { isRoomAlias }
|
||||
}
|
||||
}
|
||||
|
||||
data class RoomIdLink(
|
||||
val roomId: RoomId,
|
||||
override val viaParameters: ImmutableList<String>
|
||||
) : RoomLink
|
||||
|
||||
data class RoomAliasLink(
|
||||
val roomAlias: String,
|
||||
override val viaParameters: ImmutableList<String>
|
||||
) : RoomLink
|
||||
|
||||
sealed interface EventLink : PermalinkData {
|
||||
val eventId: EventId
|
||||
val viaParameters: ImmutableList<String>
|
||||
}
|
||||
|
||||
data class EventIdLink(
|
||||
val roomId: RoomId,
|
||||
override val eventId: EventId,
|
||||
override val viaParameters: ImmutableList<String>
|
||||
) : EventLink
|
||||
|
||||
data class EventIdAliasLink(
|
||||
val roomAlias: String,
|
||||
override val eventId: EventId,
|
||||
override val viaParameters: ImmutableList<String>
|
||||
) : EventLink
|
||||
|
||||
/*
|
||||
* &room_name=Team2
|
||||
* &room_avatar_url=mxc:
|
||||
* &inviter_name=bob
|
||||
*/
|
||||
data class RoomEmailInviteLink(
|
||||
val roomId: String,
|
||||
val roomId: RoomId,
|
||||
val email: String,
|
||||
val signUrl: String,
|
||||
val roomName: String?,
|
||||
|
|
@ -60,7 +78,7 @@ sealed interface PermalinkData {
|
|||
val roomType: String?
|
||||
) : PermalinkData
|
||||
|
||||
data class UserLink(val userId: String) : PermalinkData
|
||||
data class UserLink(val userId: UserId) : PermalinkData
|
||||
|
||||
data class FallbackLink(val uri: Uri, val isLegacyGroupLink: Boolean = false) : PermalinkData
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.permalink
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
/**
|
||||
* This class turns a uri to a [PermalinkData].
|
||||
* element-based domains (e.g. https://app.element.io/#/user/@chagai95:matrix.org) permalinks
|
||||
|
|
@ -27,12 +25,7 @@ import android.net.Uri
|
|||
interface PermalinkParser {
|
||||
/**
|
||||
* Turns a uri string to a [PermalinkData].
|
||||
*/
|
||||
fun parse(uriString: String): PermalinkData
|
||||
|
||||
/**
|
||||
* Turns a uri to a [PermalinkData].
|
||||
* https://github.com/matrix-org/matrix-doc/blob/master/proposals/1704-matrix.to-permalinks.md
|
||||
*/
|
||||
fun parse(uri: Uri): PermalinkData
|
||||
fun parse(uriString: String): PermalinkData
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,5 +22,6 @@ import io.element.android.libraries.matrix.api.core.UserId
|
|||
sealed interface Mention {
|
||||
data class User(val userId: UserId) : Mention
|
||||
data object AtRoom : Mention
|
||||
data class Room(val roomId: RoomId?, val roomAlias: String?) : Mention
|
||||
data class Room(val roomId: RoomId) : Mention
|
||||
data class RoomAlias(val roomAlias: String?) : Mention
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023 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.permalink
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import org.junit.Test
|
||||
|
||||
class PermalinkDataTest {
|
||||
@Test
|
||||
fun `getRoomId() returns value when isRoomAlias is false`() {
|
||||
val permalinkData = PermalinkData.RoomLink(
|
||||
roomIdOrAlias = "!abcdef123456:matrix.org",
|
||||
isRoomAlias = false,
|
||||
eventId = null,
|
||||
viaParameters = persistentListOf(),
|
||||
)
|
||||
assertThat(permalinkData.getRoomId()).isNotNull()
|
||||
assertThat(permalinkData.getRoomAlias()).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getRoomAlias() returns value when isRoomAlias is true`() {
|
||||
val permalinkData = PermalinkData.RoomLink(
|
||||
roomIdOrAlias = "#room:matrix.org",
|
||||
isRoomAlias = true,
|
||||
eventId = null,
|
||||
viaParameters = persistentListOf(),
|
||||
)
|
||||
assertThat(permalinkData.getRoomId()).isNull()
|
||||
assertThat(permalinkData.getRoomAlias()).isNotNull()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue