Merge pull request #3809 from element-hq/renovate/org.matrix.rustcomponents-sdk-android-0.x
fix(deps): update dependency org.matrix.rustcomponents:sdk-android to v0.2.59
This commit is contained in:
commit
1e12d2cb71
13 changed files with 56 additions and 25 deletions
|
|
@ -23,6 +23,7 @@ import io.element.android.libraries.matrix.api.core.RoomAlias
|
||||||
import io.element.android.libraries.matrix.api.room.alias.ResolvedRoomAlias
|
import io.element.android.libraries.matrix.api.room.alias.ResolvedRoomAlias
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.jvm.optionals.getOrElse
|
||||||
|
|
||||||
class RoomAliasResolverPresenter @AssistedInject constructor(
|
class RoomAliasResolverPresenter @AssistedInject constructor(
|
||||||
@Assisted private val roomAlias: RoomAlias,
|
@Assisted private val roomAlias: RoomAlias,
|
||||||
|
|
@ -57,7 +58,9 @@ class RoomAliasResolverPresenter @AssistedInject constructor(
|
||||||
|
|
||||||
private fun CoroutineScope.resolveAlias(resolveState: MutableState<AsyncData<ResolvedRoomAlias>>) = launch {
|
private fun CoroutineScope.resolveAlias(resolveState: MutableState<AsyncData<ResolvedRoomAlias>>) = launch {
|
||||||
suspend {
|
suspend {
|
||||||
matrixClient.resolveRoomAlias(roomAlias).getOrThrow()
|
matrixClient.resolveRoomAlias(roomAlias)
|
||||||
|
.getOrThrow()
|
||||||
|
.getOrElse { error("Failed to resolve room alias $roomAlias") }
|
||||||
}.runCatchingUpdatingState(resolveState)
|
}.runCatchingUpdatingState(resolveState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import io.element.android.tests.testutils.WarmUpRule
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Rule
|
import org.junit.Rule
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
class RoomAliasResolverPresenterTest {
|
class RoomAliasResolverPresenterTest {
|
||||||
@get:Rule
|
@get:Rule
|
||||||
|
|
@ -42,7 +43,7 @@ class RoomAliasResolverPresenterTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `present - resolve alias to roomId`() = runTest {
|
fun `present - resolve alias to roomId`() = runTest {
|
||||||
val result = aResolvedRoomAlias()
|
val result = Optional.of(aResolvedRoomAlias())
|
||||||
val client = FakeMatrixClient(
|
val client = FakeMatrixClient(
|
||||||
resolveRoomAliasResult = { Result.success(result) }
|
resolveRoomAliasResult = { Result.success(result) }
|
||||||
)
|
)
|
||||||
|
|
@ -54,7 +55,7 @@ class RoomAliasResolverPresenterTest {
|
||||||
assertThat(awaitItem().resolveState.isLoading()).isTrue()
|
assertThat(awaitItem().resolveState.isLoading()).isTrue()
|
||||||
val resultState = awaitItem()
|
val resultState = awaitItem()
|
||||||
assertThat(resultState.roomAlias).isEqualTo(A_ROOM_ALIAS)
|
assertThat(resultState.roomAlias).isEqualTo(A_ROOM_ALIAS)
|
||||||
assertThat(resultState.resolveState.dataOrNull()).isEqualTo(result)
|
assertThat(resultState.resolveState.dataOrNull()).isEqualTo(result.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
private const val SEARCH_BATCH_SIZE = 20
|
||||||
|
|
||||||
class RoomDirectoryPresenter @Inject constructor(
|
class RoomDirectoryPresenter @Inject constructor(
|
||||||
private val dispatchers: CoroutineDispatchers,
|
private val dispatchers: CoroutineDispatchers,
|
||||||
private val roomDirectoryService: RoomDirectoryService,
|
private val roomDirectoryService: RoomDirectoryService,
|
||||||
|
|
@ -51,7 +53,7 @@ class RoomDirectoryPresenter @Inject constructor(
|
||||||
loadingMore = false
|
loadingMore = false
|
||||||
// debounce search query
|
// debounce search query
|
||||||
delay(300)
|
delay(300)
|
||||||
roomDirectoryList.filter(searchQuery, 20)
|
roomDirectoryList.filter(filter = searchQuery, batchSize = SEARCH_BATCH_SIZE, viaServerName = null)
|
||||||
}
|
}
|
||||||
LaunchedEffect(loadingMore) {
|
LaunchedEffect(loadingMore) {
|
||||||
if (loadingMore) {
|
if (loadingMore) {
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ import org.junit.Test
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `present - emit search event`() = runTest {
|
fun `present - emit search event`() = runTest {
|
||||||
val filterLambda = lambdaRecorder { _: String?, _: Int ->
|
val filterLambda = lambdaRecorder { _: String?, _: Int, _: String? ->
|
||||||
Result.success(Unit)
|
Result.success(Unit)
|
||||||
}
|
}
|
||||||
val roomDirectoryList = FakeRoomDirectoryList(filterLambda = filterLambda)
|
val roomDirectoryList = FakeRoomDirectoryList(filterLambda = filterLambda)
|
||||||
|
|
@ -99,7 +99,7 @@ import org.junit.Test
|
||||||
}
|
}
|
||||||
assert(filterLambda)
|
assert(filterLambda)
|
||||||
.isCalledOnce()
|
.isCalledOnce()
|
||||||
.with(value("test"), any())
|
.with(value("test"), any(), value(null))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@ jsoup = "org.jsoup:jsoup:1.18.1"
|
||||||
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
|
appyx_core = { module = "com.bumble.appyx:core", version.ref = "appyx" }
|
||||||
molecule-runtime = "app.cash.molecule:molecule-runtime:2.0.0"
|
molecule-runtime = "app.cash.molecule:molecule-runtime:2.0.0"
|
||||||
timber = "com.jakewharton.timber:timber:5.0.1"
|
timber = "com.jakewharton.timber:timber:5.0.1"
|
||||||
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.2.58"
|
matrix_sdk = "org.matrix.rustcomponents:sdk-android:0.2.59"
|
||||||
matrix_richtexteditor = { module = "io.element.android:wysiwyg", version.ref = "wysiwyg" }
|
matrix_richtexteditor = { module = "io.element.android:wysiwyg", version.ref = "wysiwyg" }
|
||||||
matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose", version.ref = "wysiwyg" }
|
matrix_richtexteditor_compose = { module = "io.element.android:wysiwyg-compose", version.ref = "wysiwyg" }
|
||||||
sqldelight-driver-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
|
sqldelight-driver-android = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,14 @@ interface MatrixClient : Closeable {
|
||||||
|
|
||||||
suspend fun trackRecentlyVisitedRoom(roomId: RoomId): Result<Unit>
|
suspend fun trackRecentlyVisitedRoom(roomId: RoomId): Result<Unit>
|
||||||
suspend fun getRecentlyVisitedRooms(): Result<List<RoomId>>
|
suspend fun getRecentlyVisitedRooms(): Result<List<RoomId>>
|
||||||
suspend fun resolveRoomAlias(roomAlias: RoomAlias): Result<ResolvedRoomAlias>
|
|
||||||
|
/**
|
||||||
|
* Resolves the given room alias to a roomID (and a list of servers), if possible.
|
||||||
|
* @param roomAlias the room alias to resolve
|
||||||
|
* @return the resolved room alias if any, an empty result if not found,or an error if the resolution failed.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
suspend fun resolveRoomAlias(roomAlias: RoomAlias): Result<Optional<ResolvedRoomAlias>>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables or disables the sending queue, according to the given parameter.
|
* Enables or disables the sending queue, according to the given parameter.
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,22 @@ package io.element.android.libraries.matrix.api.roomdirectory
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface RoomDirectoryList {
|
interface RoomDirectoryList {
|
||||||
suspend fun filter(filter: String?, batchSize: Int): Result<Unit>
|
/**
|
||||||
|
* Starts a filtered search for the server.
|
||||||
|
* If the filter is not provided it will search for all the rooms. You can specify a batch_size to control the number of rooms to fetch per request.
|
||||||
|
* If the via_server is not provided it will search in the current homeserver by default.
|
||||||
|
* This method will clear the current search results and start a new one
|
||||||
|
*/
|
||||||
|
suspend fun filter(filter: String?, batchSize: Int, viaServerName: String?): Result<Unit>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load more rooms from the current search results.
|
||||||
|
*/
|
||||||
suspend fun loadMore(): Result<Unit>
|
suspend fun loadMore(): Result<Unit>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current search results as a state flow.
|
||||||
|
*/
|
||||||
val state: Flow<State>
|
val state: Flow<State>
|
||||||
|
|
||||||
data class State(
|
data class State(
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,6 @@ import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
import kotlinx.collections.immutable.toPersistentList
|
import kotlinx.collections.immutable.toPersistentList
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
|
||||||
import kotlinx.coroutines.TimeoutCancellationException
|
import kotlinx.coroutines.TimeoutCancellationException
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
|
|
@ -115,7 +114,6 @@ import org.matrix.rustcomponents.sdk.RoomPreset as RustRoomPreset
|
||||||
import org.matrix.rustcomponents.sdk.RoomVisibility as RustRoomVisibility
|
import org.matrix.rustcomponents.sdk.RoomVisibility as RustRoomVisibility
|
||||||
import org.matrix.rustcomponents.sdk.SyncService as ClientSyncService
|
import org.matrix.rustcomponents.sdk.SyncService as ClientSyncService
|
||||||
|
|
||||||
@OptIn(ExperimentalCoroutinesApi::class)
|
|
||||||
class RustMatrixClient(
|
class RustMatrixClient(
|
||||||
private val client: Client,
|
private val client: Client,
|
||||||
private val baseDirectory: File,
|
private val baseDirectory: File,
|
||||||
|
|
@ -442,13 +440,15 @@ class RustMatrixClient(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resolveRoomAlias(roomAlias: RoomAlias): Result<ResolvedRoomAlias> = withContext(sessionDispatcher) {
|
override suspend fun resolveRoomAlias(roomAlias: RoomAlias): Result<Optional<ResolvedRoomAlias>> = withContext(sessionDispatcher) {
|
||||||
runCatching {
|
runCatching {
|
||||||
val result = client.resolveRoomAlias(roomAlias.value)
|
val result = client.resolveRoomAlias(roomAlias.value)?.let {
|
||||||
ResolvedRoomAlias(
|
ResolvedRoomAlias(
|
||||||
roomId = RoomId(result.roomId),
|
roomId = RoomId(it.roomId),
|
||||||
servers = result.servers,
|
servers = it.servers,
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
Optional.ofNullable(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ class RustRoomDirectoryList(
|
||||||
.launchIn(coroutineScope)
|
.launchIn(coroutineScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun filter(filter: String?, batchSize: Int): Result<Unit> {
|
override suspend fun filter(filter: String?, batchSize: Int, viaServerName: String?): Result<Unit> {
|
||||||
return execute {
|
return execute {
|
||||||
inner.search(filter = filter, batchSize = batchSize.toUInt())
|
inner.search(filter = filter, batchSize = batchSize.toUInt(), viaServerName = viaServerName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class FakeRustRoomDirectorySearch(
|
||||||
return isAtLastPage
|
return isAtLastPage
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun search(filter: String?, batchSize: UInt) = simulateLongTask { }
|
override suspend fun search(filter: String?, batchSize: UInt, viaServerName: String?) = simulateLongTask { }
|
||||||
override suspend fun nextPage() = simulateLongTask { }
|
override suspend fun nextPage() = simulateLongTask { }
|
||||||
|
|
||||||
private var listener: RoomDirectorySearchEntriesListener? = null
|
private var listener: RoomDirectorySearchEntriesListener? = null
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class RustRoomDirectoryListTest {
|
||||||
// Let the mxCallback be ready
|
// Let the mxCallback be ready
|
||||||
runCurrent()
|
runCurrent()
|
||||||
sut.state.test {
|
sut.state.test {
|
||||||
sut.filter("", 20)
|
sut.filter(filter = "", batchSize = 20, viaServerName = null)
|
||||||
roomDirectorySearch.emitResult(
|
roomDirectorySearch.emitResult(
|
||||||
listOf(
|
listOf(
|
||||||
RoomDirectorySearchEntryUpdate.Append(listOf(aRustRoomDescription()))
|
RoomDirectorySearchEntryUpdate.Append(listOf(aRustRoomDescription()))
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,11 @@ class FakeMatrixClient(
|
||||||
private val encryptionService: FakeEncryptionService = FakeEncryptionService(),
|
private val encryptionService: FakeEncryptionService = FakeEncryptionService(),
|
||||||
private val roomDirectoryService: RoomDirectoryService = FakeRoomDirectoryService(),
|
private val roomDirectoryService: RoomDirectoryService = FakeRoomDirectoryService(),
|
||||||
private val accountManagementUrlString: Result<String?> = Result.success(null),
|
private val accountManagementUrlString: Result<String?> = Result.success(null),
|
||||||
private val resolveRoomAliasResult: (RoomAlias) -> Result<ResolvedRoomAlias> = { Result.success(ResolvedRoomAlias(A_ROOM_ID, emptyList())) },
|
private val resolveRoomAliasResult: (RoomAlias) -> Result<Optional<ResolvedRoomAlias>> = {
|
||||||
|
Result.success(
|
||||||
|
Optional.of(ResolvedRoomAlias(A_ROOM_ID, emptyList()))
|
||||||
|
)
|
||||||
|
},
|
||||||
private val getRoomPreviewResult: (RoomIdOrAlias, List<String>) -> Result<RoomPreview> = { _, _ -> Result.failure(AN_EXCEPTION) },
|
private val getRoomPreviewResult: (RoomIdOrAlias, List<String>) -> Result<RoomPreview> = { _, _ -> Result.failure(AN_EXCEPTION) },
|
||||||
private val clearCacheLambda: () -> Unit = { lambdaError() },
|
private val clearCacheLambda: () -> Unit = { lambdaError() },
|
||||||
private val userIdServerNameLambda: () -> String = { lambdaError() },
|
private val userIdServerNameLambda: () -> String = { lambdaError() },
|
||||||
|
|
@ -305,7 +309,7 @@ class FakeMatrixClient(
|
||||||
return Result.success(Unit)
|
return Result.success(Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun resolveRoomAlias(roomAlias: RoomAlias): Result<ResolvedRoomAlias> = simulateLongTask {
|
override suspend fun resolveRoomAlias(roomAlias: RoomAlias): Result<Optional<ResolvedRoomAlias>> = simulateLongTask {
|
||||||
resolveRoomAliasResult(roomAlias)
|
resolveRoomAliasResult(roomAlias)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ import kotlinx.coroutines.flow.emptyFlow
|
||||||
|
|
||||||
class FakeRoomDirectoryList(
|
class FakeRoomDirectoryList(
|
||||||
override val state: Flow<RoomDirectoryList.State> = emptyFlow(),
|
override val state: Flow<RoomDirectoryList.State> = emptyFlow(),
|
||||||
val filterLambda: (String?, Int) -> Result<Unit> = { _, _ -> Result.success(Unit) },
|
val filterLambda: (String?, Int, String?) -> Result<Unit> = { _, _, _ -> Result.success(Unit) },
|
||||||
val loadMoreLambda: () -> Result<Unit> = { Result.success(Unit) }
|
val loadMoreLambda: () -> Result<Unit> = { Result.success(Unit) }
|
||||||
) : RoomDirectoryList {
|
) : RoomDirectoryList {
|
||||||
override suspend fun filter(filter: String?, batchSize: Int) = filterLambda(filter, batchSize)
|
override suspend fun filter(filter: String?, batchSize: Int, viaServerName: String?): Result<Unit> = filterLambda(filter, batchSize, viaServerName)
|
||||||
|
|
||||||
override suspend fun loadMore(): Result<Unit> = loadMoreLambda()
|
override suspend fun loadMore(): Result<Unit> = loadMoreLambda()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue