Merge branch 'develop' into feature/bma/metro070
This commit is contained in:
commit
76493f52ec
46 changed files with 306 additions and 233 deletions
|
|
@ -41,13 +41,13 @@ import io.element.android.compound.tokens.generated.CompoundIcons
|
|||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
@Preview(widthDp = 730, heightDp = 1800)
|
||||
@Preview(widthDp = 730, heightDp = 1920)
|
||||
@Composable
|
||||
internal fun IconsCompoundPreviewLight() = ElementTheme {
|
||||
IconsCompoundPreview()
|
||||
}
|
||||
|
||||
@Preview(widthDp = 730, heightDp = 1800)
|
||||
@Preview(widthDp = 730, heightDp = 1920)
|
||||
@Composable
|
||||
internal fun IconsCompoundPreviewRtl() = ElementTheme {
|
||||
CompositionLocalProvider(
|
||||
|
|
@ -59,7 +59,7 @@ internal fun IconsCompoundPreviewRtl() = ElementTheme {
|
|||
}
|
||||
}
|
||||
|
||||
@Preview(widthDp = 730, heightDp = 1800)
|
||||
@Preview(widthDp = 730, heightDp = 1920)
|
||||
@Composable
|
||||
internal fun IconsCompoundPreviewDark() = ElementTheme(darkTheme = true) {
|
||||
IconsCompoundPreview()
|
||||
|
|
|
|||
|
|
@ -15,4 +15,5 @@ internal val iconsOther = listOf(
|
|||
R.drawable.ic_notification,
|
||||
R.drawable.ic_stop,
|
||||
R.drawable.pin,
|
||||
R.drawable.ic_winner,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -18,11 +18,8 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import androidx.compose.ui.unit.dp
|
||||
import io.element.android.compound.theme.ElementTheme
|
||||
import io.element.android.compound.tokens.generated.CompoundIcons
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
import io.element.android.libraries.designsystem.theme.components.Icon
|
||||
|
|
@ -30,53 +27,12 @@ import io.element.android.libraries.designsystem.theme.components.Text
|
|||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
internal class CompoundIconChunkProvider : PreviewParameterProvider<IconChunk> {
|
||||
override val values: Sequence<IconChunk>
|
||||
get() {
|
||||
val chunks = CompoundIcons.allResIds.chunked(36)
|
||||
return chunks.mapIndexed { index, chunk ->
|
||||
IconChunk(index = index + 1, total = chunks.size, icons = chunk.toImmutableList())
|
||||
}
|
||||
.asSequence()
|
||||
}
|
||||
}
|
||||
|
||||
internal class OtherIconChunkProvider : PreviewParameterProvider<IconChunk> {
|
||||
override val values: Sequence<IconChunk>
|
||||
get() {
|
||||
val chunks = iconsOther.chunked(36)
|
||||
return chunks.mapIndexed { index, chunk ->
|
||||
IconChunk(index = index + 1, total = chunks.size, icons = chunk.toImmutableList())
|
||||
}
|
||||
.asSequence()
|
||||
}
|
||||
}
|
||||
|
||||
internal data class IconChunk(
|
||||
val index: Int,
|
||||
val total: Int,
|
||||
val icons: ImmutableList<Int>,
|
||||
)
|
||||
|
||||
@PreviewsDayNight
|
||||
@Composable
|
||||
internal fun IconsCompoundPreview(@PreviewParameter(CompoundIconChunkProvider::class) chunk: IconChunk) = ElementPreview {
|
||||
internal fun IconsOtherPreview() = ElementPreview {
|
||||
IconsPreview(
|
||||
title = "R.drawable.ic_compound_* ${chunk.index}/${chunk.total}",
|
||||
iconsList = chunk.icons,
|
||||
iconNameTransform = { name ->
|
||||
name.removePrefix("ic_compound_")
|
||||
.replace("_", " ")
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@PreviewsDayNight
|
||||
@Composable
|
||||
internal fun IconsOtherPreview(@PreviewParameter(OtherIconChunkProvider::class) iconChunk: IconChunk) = ElementPreview {
|
||||
IconsPreview(
|
||||
title = "R.drawable.ic_* ${iconChunk.index}/${iconChunk.total}",
|
||||
iconsList = iconChunk.icons,
|
||||
title = "Other icons",
|
||||
iconsList = iconsOther.toImmutableList(),
|
||||
iconNameTransform = { name ->
|
||||
name.removePrefix("ic_")
|
||||
.replace("_", " ")
|
||||
|
|
|
|||
|
|
@ -286,7 +286,7 @@ class RustMatrixClient(
|
|||
override suspend fun getUrl(url: String): Result<ByteArray> = withContext(sessionDispatcher) {
|
||||
runCatchingExceptions {
|
||||
innerClient.getUrl(url)
|
||||
}
|
||||
}.mapFailure { it.mapClientException() }
|
||||
}
|
||||
|
||||
override suspend fun getRoom(roomId: RoomId): BaseRoom? = withContext(sessionDispatcher) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@
|
|||
package io.element.android.libraries.wellknown.api
|
||||
|
||||
interface SessionWellknownRetriever {
|
||||
suspend fun getWellKnown(): WellKnown?
|
||||
suspend fun getElementWellKnown(): ElementWellKnown?
|
||||
suspend fun getWellKnown(): WellknownRetrieverResult<WellKnown>
|
||||
suspend fun getElementWellKnown(): WellknownRetrieverResult<ElementWellKnown>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,6 @@
|
|||
package io.element.android.libraries.wellknown.api
|
||||
|
||||
interface WellknownRetriever {
|
||||
suspend fun getWellKnown(baseUrl: String): WellKnown?
|
||||
suspend fun getElementWellKnown(baseUrl: String): ElementWellKnown?
|
||||
suspend fun getWellKnown(baseUrl: String): WellknownRetrieverResult<WellKnown>
|
||||
suspend fun getElementWellKnown(baseUrl: String): WellknownRetrieverResult<ElementWellKnown>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.wellknown.api
|
||||
|
||||
sealed interface WellknownRetrieverResult<out T> {
|
||||
/**
|
||||
* Well-known data has been successfully retrieved.
|
||||
*/
|
||||
data class Success<out T>(val data: T) : WellknownRetrieverResult<T>
|
||||
|
||||
/**
|
||||
* Well-known data is not found (file does not exist server side, we got a 404).
|
||||
*/
|
||||
data object NotFound : WellknownRetrieverResult<Nothing>
|
||||
|
||||
/**
|
||||
* Any other error.
|
||||
*/
|
||||
data class Error(val exception: Exception) : WellknownRetrieverResult<Nothing>
|
||||
|
||||
fun dataOrNull(): T? = when (this) {
|
||||
is Success<T> -> data
|
||||
is Error -> null
|
||||
NotFound -> null
|
||||
}
|
||||
}
|
||||
|
|
@ -12,9 +12,11 @@ import io.element.android.libraries.androidutils.json.JsonProvider
|
|||
import io.element.android.libraries.core.extensions.mapCatchingExceptions
|
||||
import io.element.android.libraries.di.SessionScope
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import io.element.android.libraries.matrix.api.exception.ClientException
|
||||
import io.element.android.libraries.wellknown.api.ElementWellKnown
|
||||
import io.element.android.libraries.wellknown.api.SessionWellknownRetriever
|
||||
import io.element.android.libraries.wellknown.api.WellKnown
|
||||
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
|
||||
import timber.log.Timber
|
||||
|
||||
@ContributesBinding(SessionScope::class)
|
||||
|
|
@ -24,29 +26,40 @@ class DefaultSessionWellknownRetriever(
|
|||
) : SessionWellknownRetriever {
|
||||
private val domain by lazy { matrixClient.userIdServerName() }
|
||||
|
||||
override suspend fun getWellKnown(): WellKnown? {
|
||||
override suspend fun getWellKnown(): WellknownRetrieverResult<WellKnown> {
|
||||
val url = "https://$domain/.well-known/matrix/client"
|
||||
return matrixClient
|
||||
.getUrl(url)
|
||||
.mapCatchingExceptions {
|
||||
val data = String(it)
|
||||
json().decodeFromString(InternalWellKnown.serializer(), data)
|
||||
json().decodeFromString<InternalWellKnown>(data).map()
|
||||
}
|
||||
.onFailure { Timber.e(it, "Failed to retrieve .well-known from $domain") }
|
||||
.map { it.map() }
|
||||
.getOrNull()
|
||||
.toWellknownRetrieverResult()
|
||||
}
|
||||
|
||||
override suspend fun getElementWellKnown(): ElementWellKnown? {
|
||||
override suspend fun getElementWellKnown(): WellknownRetrieverResult<ElementWellKnown> {
|
||||
val url = "https://$domain/.well-known/element/element.json"
|
||||
return matrixClient
|
||||
.getUrl(url)
|
||||
.mapCatchingExceptions {
|
||||
val data = String(it)
|
||||
json().decodeFromString(InternalElementWellKnown.serializer(), data)
|
||||
json().decodeFromString<InternalElementWellKnown>(data).map()
|
||||
}
|
||||
.onFailure { Timber.e(it, "Failed to retrieve Element .well-known from $domain") }
|
||||
.map { it.map() }
|
||||
.getOrNull()
|
||||
.toWellknownRetrieverResult()
|
||||
}
|
||||
|
||||
private fun <T> Result<T>.toWellknownRetrieverResult(): WellknownRetrieverResult<T> = fold(
|
||||
onSuccess = {
|
||||
WellknownRetrieverResult.Success(it)
|
||||
},
|
||||
onFailure = {
|
||||
Timber.e(it, "Failed to retrieve Element .well-known from $domain")
|
||||
// This check on message value is not ideal but this is what we got from the SDK.
|
||||
if ((it as? ClientException.Generic)?.message?.contains("404") == true) {
|
||||
WellknownRetrieverResult.NotFound
|
||||
} else {
|
||||
WellknownRetrieverResult.Error(it as Exception)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,45 +9,71 @@ package io.element.android.libraries.wellknown.impl
|
|||
|
||||
import dev.zacsweers.metro.AppScope
|
||||
import dev.zacsweers.metro.ContributesBinding
|
||||
import io.element.android.libraries.core.extensions.runCatchingExceptions
|
||||
import io.element.android.libraries.core.uri.ensureProtocol
|
||||
import io.element.android.libraries.network.RetrofitFactory
|
||||
import io.element.android.libraries.wellknown.api.ElementWellKnown
|
||||
import io.element.android.libraries.wellknown.api.WellKnown
|
||||
import io.element.android.libraries.wellknown.api.WellknownRetriever
|
||||
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
|
||||
import retrofit2.HttpException
|
||||
import timber.log.Timber
|
||||
import java.net.HttpURLConnection
|
||||
|
||||
@ContributesBinding(AppScope::class)
|
||||
class DefaultWellknownRetriever(
|
||||
private val retrofitFactory: RetrofitFactory,
|
||||
) : WellknownRetriever {
|
||||
override suspend fun getWellKnown(baseUrl: String): WellKnown? {
|
||||
val wellknownApi = buildWellknownApi(baseUrl) ?: return null
|
||||
return try {
|
||||
wellknownApi.getWellKnown().map()
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Failed to retrieve well-known data for $baseUrl")
|
||||
null
|
||||
}
|
||||
override suspend fun getWellKnown(baseUrl: String): WellknownRetrieverResult<WellKnown> {
|
||||
return buildWellknownApi(baseUrl)
|
||||
.map { wellknownApi ->
|
||||
try {
|
||||
val result = wellknownApi.getWellKnown().map()
|
||||
WellknownRetrieverResult.Success(result)
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Failed to retrieve well-known data for $baseUrl")
|
||||
if ((e as? HttpException)?.code() == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||
WellknownRetrieverResult.NotFound
|
||||
} else {
|
||||
WellknownRetrieverResult.Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
.fold(
|
||||
onSuccess = { it },
|
||||
onFailure = { WellknownRetrieverResult.Error(it as Exception) }
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun getElementWellKnown(baseUrl: String): ElementWellKnown? {
|
||||
val wellknownApi = buildWellknownApi(baseUrl) ?: return null
|
||||
return try {
|
||||
wellknownApi.getElementWellKnown().map()
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Failed to retrieve Element well-known data for $baseUrl")
|
||||
null
|
||||
}
|
||||
override suspend fun getElementWellKnown(baseUrl: String): WellknownRetrieverResult<ElementWellKnown> {
|
||||
return buildWellknownApi(baseUrl)
|
||||
.map { wellknownApi ->
|
||||
try {
|
||||
val result = wellknownApi.getElementWellKnown().map()
|
||||
WellknownRetrieverResult.Success(result)
|
||||
} catch (e: Exception) {
|
||||
// Is it a 404?
|
||||
Timber.e(e, "Failed to retrieve Element well-known data for $baseUrl")
|
||||
if ((e as? HttpException)?.code() == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||
WellknownRetrieverResult.NotFound
|
||||
} else {
|
||||
WellknownRetrieverResult.Error(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
.fold(
|
||||
onSuccess = { it },
|
||||
onFailure = { WellknownRetrieverResult.Error(it as Exception) }
|
||||
)
|
||||
}
|
||||
|
||||
private fun buildWellknownApi(accountProviderUrl: String): WellknownAPI? {
|
||||
return try {
|
||||
private fun buildWellknownApi(accountProviderUrl: String): Result<WellknownAPI> {
|
||||
return runCatchingExceptions {
|
||||
retrofitFactory.create(accountProviderUrl.ensureProtocol())
|
||||
.create(WellknownAPI::class.java)
|
||||
} catch (e: Exception) {
|
||||
}.onFailure { e ->
|
||||
// If the base URL is not valid, we cannot retrieve the well-known data
|
||||
Timber.e(e, "Failed to create Retrofit instance for $accountProviderUrl")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import io.element.android.libraries.matrix.test.FakeMatrixClient
|
|||
import io.element.android.libraries.wellknown.api.ElementWellKnown
|
||||
import io.element.android.libraries.wellknown.api.WellKnown
|
||||
import io.element.android.libraries.wellknown.api.WellKnownBaseConfig
|
||||
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
|
||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||
import io.element.android.tests.testutils.lambda.value
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
|
@ -29,9 +30,11 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
getUrlLambda = getUrlLambda,
|
||||
)
|
||||
assertThat(sut.getWellKnown()).isEqualTo(
|
||||
WellKnown(
|
||||
homeServer = null,
|
||||
identityServer = null,
|
||||
WellknownRetrieverResult.Success(
|
||||
WellKnown(
|
||||
homeServer = null,
|
||||
identityServer = null,
|
||||
)
|
||||
)
|
||||
)
|
||||
getUrlLambda.assertions().isCalledOnce()
|
||||
|
|
@ -55,13 +58,15 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
}
|
||||
)
|
||||
assertThat(sut.getWellKnown()).isEqualTo(
|
||||
WellKnown(
|
||||
homeServer = WellKnownBaseConfig(
|
||||
baseURL = "https://example.org",
|
||||
),
|
||||
identityServer = WellKnownBaseConfig(
|
||||
baseURL = "https://identity.example.org",
|
||||
),
|
||||
WellknownRetrieverResult.Success(
|
||||
WellKnown(
|
||||
homeServer = WellKnownBaseConfig(
|
||||
baseURL = "https://example.org",
|
||||
),
|
||||
identityServer = WellKnownBaseConfig(
|
||||
baseURL = "https://identity.example.org",
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -81,13 +86,15 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
}
|
||||
)
|
||||
assertThat(sut.getWellKnown()).isEqualTo(
|
||||
WellKnown(
|
||||
homeServer = WellKnownBaseConfig(
|
||||
baseURL = "https://example.org",
|
||||
),
|
||||
identityServer = WellKnownBaseConfig(
|
||||
baseURL = null,
|
||||
),
|
||||
WellknownRetrieverResult.Success(
|
||||
WellKnown(
|
||||
homeServer = WellKnownBaseConfig(
|
||||
baseURL = "https://example.org",
|
||||
),
|
||||
identityServer = WellKnownBaseConfig(
|
||||
baseURL = null,
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -110,13 +117,15 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
},
|
||||
)
|
||||
assertThat(sut.getWellKnown()).isEqualTo(
|
||||
WellKnown(
|
||||
homeServer = WellKnownBaseConfig(
|
||||
baseURL = "https://example.org",
|
||||
),
|
||||
identityServer = WellKnownBaseConfig(
|
||||
baseURL = "https://identity.example.org",
|
||||
),
|
||||
WellknownRetrieverResult.Success(
|
||||
WellKnown(
|
||||
homeServer = WellKnownBaseConfig(
|
||||
baseURL = "https://example.org",
|
||||
),
|
||||
identityServer = WellKnownBaseConfig(
|
||||
baseURL = "https://identity.example.org",
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -135,7 +144,7 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
)
|
||||
}
|
||||
)
|
||||
assertThat(sut.getWellKnown()).isNull()
|
||||
assertThat(sut.getWellKnown()).isInstanceOf(WellknownRetrieverResult.Error::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -145,7 +154,7 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
Result.failure(AN_EXCEPTION)
|
||||
}
|
||||
)
|
||||
assertThat(sut.getWellKnown()).isNull()
|
||||
assertThat(sut.getWellKnown()).isInstanceOf(WellknownRetrieverResult.Error::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -157,11 +166,13 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
getUrlLambda = getUrlLambda,
|
||||
)
|
||||
assertThat(sut.getElementWellKnown()).isEqualTo(
|
||||
ElementWellKnown(
|
||||
registrationHelperUrl = null,
|
||||
enforceElementPro = null,
|
||||
rageshakeUrl = null,
|
||||
brandColor = null,
|
||||
WellknownRetrieverResult.Success(
|
||||
ElementWellKnown(
|
||||
registrationHelperUrl = null,
|
||||
enforceElementPro = null,
|
||||
rageshakeUrl = null,
|
||||
brandColor = null,
|
||||
)
|
||||
)
|
||||
)
|
||||
getUrlLambda.assertions().isCalledOnce()
|
||||
|
|
@ -183,11 +194,13 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
}
|
||||
)
|
||||
assertThat(sut.getElementWellKnown()).isEqualTo(
|
||||
ElementWellKnown(
|
||||
registrationHelperUrl = "a_registration_url",
|
||||
enforceElementPro = true,
|
||||
rageshakeUrl = "a_rageshake_url",
|
||||
brandColor = "#FF0000",
|
||||
WellknownRetrieverResult.Success(
|
||||
ElementWellKnown(
|
||||
registrationHelperUrl = "a_registration_url",
|
||||
enforceElementPro = true,
|
||||
rageshakeUrl = "a_rageshake_url",
|
||||
brandColor = "#FF0000",
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -207,11 +220,13 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
},
|
||||
)
|
||||
assertThat(sut.getElementWellKnown()).isEqualTo(
|
||||
ElementWellKnown(
|
||||
registrationHelperUrl = "a_registration_url",
|
||||
enforceElementPro = true,
|
||||
rageshakeUrl = "a_rageshake_url",
|
||||
brandColor = null,
|
||||
WellknownRetrieverResult.Success(
|
||||
ElementWellKnown(
|
||||
registrationHelperUrl = "a_registration_url",
|
||||
enforceElementPro = true,
|
||||
rageshakeUrl = "a_rageshake_url",
|
||||
brandColor = null,
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
@ -228,7 +243,7 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
)
|
||||
}
|
||||
)
|
||||
assertThat(sut.getElementWellKnown()).isNull()
|
||||
assertThat(sut.getElementWellKnown()).isInstanceOf(WellknownRetrieverResult.Error::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -238,7 +253,7 @@ class DefaultSessionWellknownRetrieverTest {
|
|||
Result.failure(AN_EXCEPTION)
|
||||
}
|
||||
)
|
||||
assertThat(sut.getElementWellKnown()).isNull()
|
||||
assertThat(sut.getElementWellKnown()).isInstanceOf(WellknownRetrieverResult.Error::class.java)
|
||||
}
|
||||
|
||||
private fun createDefaultSessionWellknownRetriever(
|
||||
|
|
|
|||
|
|
@ -10,17 +10,18 @@ package io.element.android.features.wellknown.test
|
|||
import io.element.android.libraries.wellknown.api.ElementWellKnown
|
||||
import io.element.android.libraries.wellknown.api.SessionWellknownRetriever
|
||||
import io.element.android.libraries.wellknown.api.WellKnown
|
||||
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
|
||||
import io.element.android.tests.testutils.simulateLongTask
|
||||
|
||||
class FakeSessionWellknownRetriever(
|
||||
private val getWellKnownResult: () -> WellKnown? = { null },
|
||||
private val getElementWellKnownResult: () -> ElementWellKnown? = { null },
|
||||
private val getWellKnownResult: () -> WellknownRetrieverResult<WellKnown> = { WellknownRetrieverResult.NotFound },
|
||||
private val getElementWellKnownResult: () -> WellknownRetrieverResult<ElementWellKnown> = { WellknownRetrieverResult.NotFound },
|
||||
) : SessionWellknownRetriever {
|
||||
override suspend fun getWellKnown(): WellKnown? = simulateLongTask {
|
||||
override suspend fun getWellKnown(): WellknownRetrieverResult<WellKnown> = simulateLongTask {
|
||||
getWellKnownResult()
|
||||
}
|
||||
|
||||
override suspend fun getElementWellKnown(): ElementWellKnown? = simulateLongTask {
|
||||
override suspend fun getElementWellKnown(): WellknownRetrieverResult<ElementWellKnown> = simulateLongTask {
|
||||
getElementWellKnownResult()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,17 +10,18 @@ package io.element.android.features.wellknown.test
|
|||
import io.element.android.libraries.wellknown.api.ElementWellKnown
|
||||
import io.element.android.libraries.wellknown.api.WellKnown
|
||||
import io.element.android.libraries.wellknown.api.WellknownRetriever
|
||||
import io.element.android.libraries.wellknown.api.WellknownRetrieverResult
|
||||
import io.element.android.tests.testutils.simulateLongTask
|
||||
|
||||
class FakeWellknownRetriever(
|
||||
private val getWellKnownResult: (String) -> WellKnown? = { null },
|
||||
private val getElementWellKnownResult: (String) -> ElementWellKnown? = { null },
|
||||
private val getWellKnownResult: (String) -> WellknownRetrieverResult<WellKnown> = { WellknownRetrieverResult.NotFound },
|
||||
private val getElementWellKnownResult: (String) -> WellknownRetrieverResult<ElementWellKnown> = { WellknownRetrieverResult.NotFound },
|
||||
) : WellknownRetriever {
|
||||
override suspend fun getWellKnown(baseUrl: String): WellKnown? = simulateLongTask {
|
||||
override suspend fun getWellKnown(baseUrl: String): WellknownRetrieverResult<WellKnown> = simulateLongTask {
|
||||
getWellKnownResult(baseUrl)
|
||||
}
|
||||
|
||||
override suspend fun getElementWellKnown(baseUrl: String): ElementWellKnown? = simulateLongTask {
|
||||
override suspend fun getElementWellKnown(baseUrl: String): WellknownRetrieverResult<ElementWellKnown> = simulateLongTask {
|
||||
getElementWellKnownResult(baseUrl)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue