Handle tapping on user mentions (#2021)
This commit is contained in:
parent
6acdc88285
commit
2492584786
8 changed files with 92 additions and 14 deletions
|
|
@ -18,6 +18,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.RoomId
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
/**
|
||||
|
|
@ -32,7 +33,15 @@ sealed interface PermalinkData {
|
|||
val isRoomAlias: Boolean,
|
||||
val eventId: String?,
|
||||
val viaParameters: ImmutableList<String>
|
||||
) : PermalinkData
|
||||
) : PermalinkData {
|
||||
fun getRoomId(): RoomId? {
|
||||
return roomIdOrAlias.takeIf { !isRoomAlias }?.let(::RoomId)
|
||||
}
|
||||
|
||||
fun getRoomAlias(): String? {
|
||||
return roomIdOrAlias.takeIf { isRoomAlias }
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* &room_name=Team2
|
||||
|
|
|
|||
|
|
@ -16,7 +16,11 @@
|
|||
|
||||
package io.element.android.libraries.matrix.api.room
|
||||
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.core.UserId
|
||||
|
||||
sealed interface Mention {
|
||||
data class User(val userId: String): Mention
|
||||
data class User(val userId: UserId): Mention
|
||||
data object AtRoom: Mention
|
||||
data class Room(val roomId: RoomId?, val roomAlias: String?): Mention
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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