Room Directory : start exposing the matrix apis
This commit is contained in:
parent
3d071f0765
commit
21dfb46b1e
12 changed files with 411 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ import io.element.android.libraries.matrix.api.oidc.AccountManagementAction
|
||||||
import io.element.android.libraries.matrix.api.pusher.PushersService
|
import io.element.android.libraries.matrix.api.pusher.PushersService
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||||
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectoryService
|
||||||
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
||||||
import io.element.android.libraries.matrix.api.sync.SyncService
|
import io.element.android.libraries.matrix.api.sync.SyncService
|
||||||
import io.element.android.libraries.matrix.api.user.MatrixSearchUserResults
|
import io.element.android.libraries.matrix.api.user.MatrixSearchUserResults
|
||||||
|
|
@ -64,6 +65,7 @@ interface MatrixClient : Closeable {
|
||||||
fun notificationService(): NotificationService
|
fun notificationService(): NotificationService
|
||||||
fun notificationSettingsService(): NotificationSettingsService
|
fun notificationSettingsService(): NotificationSettingsService
|
||||||
fun encryptionService(): EncryptionService
|
fun encryptionService(): EncryptionService
|
||||||
|
fun roomDirectoryService(): RoomDirectoryService
|
||||||
suspend fun getCacheSize(): Long
|
suspend fun getCacheSize(): Long
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* 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.roomdirectory
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
|
|
||||||
|
data class RoomDescription(
|
||||||
|
val roomId: RoomId,
|
||||||
|
val name: String?,
|
||||||
|
val topic: String?,
|
||||||
|
val alias: String?,
|
||||||
|
val avatarUrl: String?,
|
||||||
|
val joinRule: JoinRule,
|
||||||
|
val isWorldReadable: Boolean,
|
||||||
|
val joinedMembers: Long
|
||||||
|
) {
|
||||||
|
enum class JoinRule {
|
||||||
|
PUBLIC,
|
||||||
|
KNOCK,
|
||||||
|
UNKNOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* 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.roomdirectory
|
||||||
|
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
|
||||||
|
interface RoomDirectorySearch {
|
||||||
|
suspend fun updateQuery(query: String?, batchSize: Int)
|
||||||
|
suspend fun loadMore()
|
||||||
|
suspend fun hasMoreToLoad(): Boolean
|
||||||
|
val results: SharedFlow<List<RoomDescription>>
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* 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.roomdirectory
|
||||||
|
|
||||||
|
interface RoomDirectoryService {
|
||||||
|
fun search(): RoomDirectorySearch
|
||||||
|
}
|
||||||
|
|
@ -35,6 +35,7 @@ import io.element.android.libraries.matrix.api.oidc.AccountManagementAction
|
||||||
import io.element.android.libraries.matrix.api.pusher.PushersService
|
import io.element.android.libraries.matrix.api.pusher.PushersService
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||||
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectoryService
|
||||||
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
||||||
import io.element.android.libraries.matrix.api.roomlist.awaitLoaded
|
import io.element.android.libraries.matrix.api.roomlist.awaitLoaded
|
||||||
import io.element.android.libraries.matrix.api.sync.SyncService
|
import io.element.android.libraries.matrix.api.sync.SyncService
|
||||||
|
|
@ -53,6 +54,7 @@ import io.element.android.libraries.matrix.impl.room.MatrixRoomInfoMapper
|
||||||
import io.element.android.libraries.matrix.impl.room.RoomContentForwarder
|
import io.element.android.libraries.matrix.impl.room.RoomContentForwarder
|
||||||
import io.element.android.libraries.matrix.impl.room.RoomSyncSubscriber
|
import io.element.android.libraries.matrix.impl.room.RoomSyncSubscriber
|
||||||
import io.element.android.libraries.matrix.impl.room.RustMatrixRoom
|
import io.element.android.libraries.matrix.impl.room.RustMatrixRoom
|
||||||
|
import io.element.android.libraries.matrix.impl.roomdirectory.RustRoomDirectoryService
|
||||||
import io.element.android.libraries.matrix.impl.roomlist.RoomListFactory
|
import io.element.android.libraries.matrix.impl.roomlist.RoomListFactory
|
||||||
import io.element.android.libraries.matrix.impl.roomlist.RustRoomListService
|
import io.element.android.libraries.matrix.impl.roomlist.RustRoomListService
|
||||||
import io.element.android.libraries.matrix.impl.roomlist.fullRoomWithTimeline
|
import io.element.android.libraries.matrix.impl.roomlist.fullRoomWithTimeline
|
||||||
|
|
@ -150,6 +152,13 @@ class RustMatrixClient(
|
||||||
sessionCoroutineScope = sessionCoroutineScope,
|
sessionCoroutineScope = sessionCoroutineScope,
|
||||||
dispatchers = dispatchers,
|
dispatchers = dispatchers,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val roomDirectoryService = RustRoomDirectoryService(
|
||||||
|
client = client,
|
||||||
|
sessionCoroutineScope = sessionCoroutineScope,
|
||||||
|
sessionDispatcher = sessionDispatcher,
|
||||||
|
)
|
||||||
|
|
||||||
private val sessionDirectoryNameProvider = SessionDirectoryNameProvider()
|
private val sessionDirectoryNameProvider = SessionDirectoryNameProvider()
|
||||||
|
|
||||||
private val isLoggingOut = AtomicBoolean(false)
|
private val isLoggingOut = AtomicBoolean(false)
|
||||||
|
|
@ -428,6 +437,8 @@ class RustMatrixClient(
|
||||||
|
|
||||||
override fun notificationSettingsService(): NotificationSettingsService = notificationSettingsService
|
override fun notificationSettingsService(): NotificationSettingsService = notificationSettingsService
|
||||||
|
|
||||||
|
override fun roomDirectoryService(): RoomDirectoryService = roomDirectoryService
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
sessionCoroutineScope.cancel()
|
sessionCoroutineScope.cancel()
|
||||||
clientDelegateTaskHandle?.cancelAndDestroy()
|
clientDelegateTaskHandle?.cancelAndDestroy()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* 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.impl.roomdirectory
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDescription
|
||||||
|
import org.matrix.rustcomponents.sdk.PublicRoomJoinRule
|
||||||
|
import org.matrix.rustcomponents.sdk.RoomDescription as RustRoomDescription
|
||||||
|
|
||||||
|
class RoomDescriptionMapper {
|
||||||
|
|
||||||
|
fun map(roomDescription: RustRoomDescription): RoomDescription {
|
||||||
|
return RoomDescription(
|
||||||
|
roomId = RoomId(roomDescription.roomId),
|
||||||
|
name = roomDescription.name,
|
||||||
|
topic = roomDescription.topic,
|
||||||
|
avatarUrl = roomDescription.avatarUrl,
|
||||||
|
alias = roomDescription.alias,
|
||||||
|
joinRule = when (roomDescription.joinRule) {
|
||||||
|
PublicRoomJoinRule.PUBLIC -> RoomDescription.JoinRule.PUBLIC
|
||||||
|
PublicRoomJoinRule.KNOCK -> RoomDescription.JoinRule.KNOCK
|
||||||
|
null -> RoomDescription.JoinRule.UNKNOWN
|
||||||
|
},
|
||||||
|
isWorldReadable = roomDescription.isWorldReadable,
|
||||||
|
joinedMembers = roomDescription.joinedMembers.toLong(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* 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.impl.roomdirectory
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.impl.util.cancelAndDestroy
|
||||||
|
import kotlinx.coroutines.channels.Channel
|
||||||
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
|
import kotlinx.coroutines.channels.trySendBlocking
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.buffer
|
||||||
|
import kotlinx.coroutines.flow.callbackFlow
|
||||||
|
import kotlinx.coroutines.flow.catch
|
||||||
|
import org.matrix.rustcomponents.sdk.RoomDirectorySearch
|
||||||
|
import org.matrix.rustcomponents.sdk.RoomDirectorySearchEntriesListener
|
||||||
|
import org.matrix.rustcomponents.sdk.RoomDirectorySearchEntryUpdate
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
internal fun RoomDirectorySearch.resultsFlow(): Flow<List<RoomDirectorySearchEntryUpdate>> =
|
||||||
|
callbackFlow {
|
||||||
|
val listener = object : RoomDirectorySearchEntriesListener {
|
||||||
|
override fun onUpdate(roomEntriesUpdate: List<RoomDirectorySearchEntryUpdate>) {
|
||||||
|
trySendBlocking(roomEntriesUpdate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val result = results(listener)
|
||||||
|
awaitClose {
|
||||||
|
result.cancelAndDestroy()
|
||||||
|
}
|
||||||
|
}.catch {
|
||||||
|
Timber.d(it, "timelineDiffFlow() failed")
|
||||||
|
}.buffer(Channel.UNLIMITED)
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
/*
|
||||||
|
* 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.impl.roomdirectory
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDescription
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import org.matrix.rustcomponents.sdk.RoomDirectorySearchEntryUpdate
|
||||||
|
import timber.log.Timber
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
|
||||||
|
class RoomDirectorySearchProcessor(
|
||||||
|
private val roomDescriptions: MutableSharedFlow<List<RoomDescription>>,
|
||||||
|
private val coroutineContext: CoroutineContext,
|
||||||
|
private val roomDescriptionMapper: RoomDescriptionMapper,
|
||||||
|
) {
|
||||||
|
|
||||||
|
private val mutex = Mutex()
|
||||||
|
|
||||||
|
suspend fun postUpdates(updates: List<RoomDirectorySearchEntryUpdate>) {
|
||||||
|
updateRoomDescriptions {
|
||||||
|
Timber.v("Update room descriptions from postUpdates (with ${updates.size} items) on ${Thread.currentThread()}")
|
||||||
|
updates.forEach { update ->
|
||||||
|
applyUpdate(update)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun MutableList<RoomDescription>.applyUpdate(update: RoomDirectorySearchEntryUpdate) {
|
||||||
|
when (update) {
|
||||||
|
is RoomDirectorySearchEntryUpdate.Append -> {
|
||||||
|
val roomSummaries = update.values.map(roomDescriptionMapper::map)
|
||||||
|
addAll(roomSummaries)
|
||||||
|
}
|
||||||
|
is RoomDirectorySearchEntryUpdate.PushBack -> {
|
||||||
|
val roomSummary = roomDescriptionMapper.map(update.value)
|
||||||
|
add(roomSummary)
|
||||||
|
}
|
||||||
|
is RoomDirectorySearchEntryUpdate.PushFront -> {
|
||||||
|
val roomSummary = roomDescriptionMapper.map(update.value)
|
||||||
|
add(0, roomSummary)
|
||||||
|
}
|
||||||
|
is RoomDirectorySearchEntryUpdate.Set -> {
|
||||||
|
val roomSummary = roomDescriptionMapper.map(update.value)
|
||||||
|
this[update.index.toInt()] = roomSummary
|
||||||
|
}
|
||||||
|
is RoomDirectorySearchEntryUpdate.Insert -> {
|
||||||
|
val roomSummary = roomDescriptionMapper.map(update.value)
|
||||||
|
add(update.index.toInt(), roomSummary)
|
||||||
|
}
|
||||||
|
is RoomDirectorySearchEntryUpdate.Remove -> {
|
||||||
|
removeAt(update.index.toInt())
|
||||||
|
}
|
||||||
|
is RoomDirectorySearchEntryUpdate.Reset -> {
|
||||||
|
clear()
|
||||||
|
addAll(update.values.map(roomDescriptionMapper::map))
|
||||||
|
}
|
||||||
|
RoomDirectorySearchEntryUpdate.PopBack -> {
|
||||||
|
removeLastOrNull()
|
||||||
|
}
|
||||||
|
RoomDirectorySearchEntryUpdate.PopFront -> {
|
||||||
|
removeFirstOrNull()
|
||||||
|
}
|
||||||
|
RoomDirectorySearchEntryUpdate.Clear -> {
|
||||||
|
clear()
|
||||||
|
}
|
||||||
|
is RoomDirectorySearchEntryUpdate.Truncate -> {
|
||||||
|
subList(update.length.toInt(), size).clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun updateRoomDescriptions(block: suspend MutableList<RoomDescription>.() -> Unit) = withContext(coroutineContext) {
|
||||||
|
mutex.withLock {
|
||||||
|
val current = roomDescriptions.replayCache.lastOrNull()
|
||||||
|
val mutableRoomSummaries = current.orEmpty().toMutableList()
|
||||||
|
block(mutableRoomSummaries)
|
||||||
|
roomDescriptions.emit(mutableRoomSummaries)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* 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.impl.roomdirectory
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDescription
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectorySearch
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
|
import kotlinx.coroutines.flow.launchIn
|
||||||
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.matrix.rustcomponents.sdk.RoomDirectorySearch as InnerRoomDirectorySearch
|
||||||
|
|
||||||
|
class RustRoomDirectorySearch(
|
||||||
|
private val inner: InnerRoomDirectorySearch,
|
||||||
|
private val sessionCoroutineScope: CoroutineScope,
|
||||||
|
private val sessionDispatcher: CoroutineDispatcher,
|
||||||
|
) : RoomDirectorySearch {
|
||||||
|
|
||||||
|
private val _results: MutableStateFlow<List<RoomDescription>> =
|
||||||
|
MutableStateFlow(emptyList())
|
||||||
|
|
||||||
|
private val processor = RoomDirectorySearchProcessor(_results, sessionDispatcher, RoomDescriptionMapper())
|
||||||
|
|
||||||
|
init {
|
||||||
|
sessionCoroutineScope.launch(sessionDispatcher) {
|
||||||
|
inner
|
||||||
|
.resultsFlow()
|
||||||
|
.onEach { updates ->
|
||||||
|
processor.postUpdates(updates)
|
||||||
|
}
|
||||||
|
.launchIn(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun updateQuery(query: String?, batchSize: Int) {
|
||||||
|
inner.search(query, batchSize.toUInt())
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun loadMore() {
|
||||||
|
inner.nextPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun hasMoreToLoad(): Boolean {
|
||||||
|
return !inner.isAtLastPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
override val results: SharedFlow<List<RoomDescription>> = _results
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* 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.impl.roomdirectory
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectorySearch
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectoryService
|
||||||
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import org.matrix.rustcomponents.sdk.Client
|
||||||
|
|
||||||
|
class RustRoomDirectoryService(
|
||||||
|
private val client: Client,
|
||||||
|
private val sessionCoroutineScope: CoroutineScope,
|
||||||
|
private val sessionDispatcher: CoroutineDispatcher,
|
||||||
|
) : RoomDirectoryService {
|
||||||
|
|
||||||
|
override fun search(): RoomDirectorySearch {
|
||||||
|
return RustRoomDirectorySearch(client.roomDirectorySearch(), sessionCoroutineScope, sessionDispatcher)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,7 @@ import io.element.android.libraries.matrix.api.oidc.AccountManagementAction
|
||||||
import io.element.android.libraries.matrix.api.pusher.PushersService
|
import io.element.android.libraries.matrix.api.pusher.PushersService
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||||
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectoryService
|
||||||
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
||||||
import io.element.android.libraries.matrix.api.user.MatrixSearchUserResults
|
import io.element.android.libraries.matrix.api.user.MatrixSearchUserResults
|
||||||
import io.element.android.libraries.matrix.api.user.MatrixUser
|
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||||
|
|
@ -39,6 +40,7 @@ import io.element.android.libraries.matrix.test.media.FakeMediaLoader
|
||||||
import io.element.android.libraries.matrix.test.notification.FakeNotificationService
|
import io.element.android.libraries.matrix.test.notification.FakeNotificationService
|
||||||
import io.element.android.libraries.matrix.test.notificationsettings.FakeNotificationSettingsService
|
import io.element.android.libraries.matrix.test.notificationsettings.FakeNotificationSettingsService
|
||||||
import io.element.android.libraries.matrix.test.pushers.FakePushersService
|
import io.element.android.libraries.matrix.test.pushers.FakePushersService
|
||||||
|
import io.element.android.libraries.matrix.test.roomdirectory.FakeRoomDirectoryService
|
||||||
import io.element.android.libraries.matrix.test.roomlist.FakeRoomListService
|
import io.element.android.libraries.matrix.test.roomlist.FakeRoomListService
|
||||||
import io.element.android.libraries.matrix.test.sync.FakeSyncService
|
import io.element.android.libraries.matrix.test.sync.FakeSyncService
|
||||||
import io.element.android.libraries.matrix.test.verification.FakeSessionVerificationService
|
import io.element.android.libraries.matrix.test.verification.FakeSessionVerificationService
|
||||||
|
|
@ -65,6 +67,7 @@ class FakeMatrixClient(
|
||||||
private val notificationSettingsService: FakeNotificationSettingsService = FakeNotificationSettingsService(),
|
private val notificationSettingsService: FakeNotificationSettingsService = FakeNotificationSettingsService(),
|
||||||
private val syncService: FakeSyncService = FakeSyncService(),
|
private val syncService: FakeSyncService = FakeSyncService(),
|
||||||
private val encryptionService: FakeEncryptionService = FakeEncryptionService(),
|
private val encryptionService: FakeEncryptionService = FakeEncryptionService(),
|
||||||
|
private val roomDirectoryService: RoomDirectoryService = FakeRoomDirectoryService(),
|
||||||
private val accountManagementUrlString: Result<String?> = Result.success(null),
|
private val accountManagementUrlString: Result<String?> = Result.success(null),
|
||||||
) : MatrixClient {
|
) : MatrixClient {
|
||||||
var setDisplayNameCalled: Boolean = false
|
var setDisplayNameCalled: Boolean = false
|
||||||
|
|
@ -126,6 +129,8 @@ class FakeMatrixClient(
|
||||||
|
|
||||||
override fun syncService() = syncService
|
override fun syncService() = syncService
|
||||||
|
|
||||||
|
override fun roomDirectoryService() = roomDirectoryService
|
||||||
|
|
||||||
override suspend fun getCacheSize(): Long {
|
override suspend fun getCacheSize(): Long {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* 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.test.roomdirectory
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectorySearch
|
||||||
|
import io.element.android.libraries.matrix.api.roomdirectory.RoomDirectoryService
|
||||||
|
|
||||||
|
class FakeRoomDirectoryService : RoomDirectoryService {
|
||||||
|
override fun search(): RoomDirectorySearch {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue