sdk : allow passing coroutineScope to RoomList
This commit is contained in:
parent
941340f250
commit
edba196a69
15 changed files with 83 additions and 35 deletions
|
|
@ -10,6 +10,7 @@ package io.element.android.libraries.matrix.api.roomlist
|
|||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.filterIsInstance
|
||||
|
|
@ -39,11 +40,13 @@ interface RoomListService {
|
|||
* @param pageSize the number of rooms to load at once.
|
||||
* @param initialFilter the initial filter to apply to the rooms.
|
||||
* @param source the source of the rooms, either all rooms or invites.
|
||||
* @param coroutineScope the coroutine scope to use for the room list operations.
|
||||
*/
|
||||
fun createRoomList(
|
||||
pageSize: Int,
|
||||
initialFilter: RoomListFilter,
|
||||
source: RoomList.Source,
|
||||
coroutineScope: CoroutineScope,
|
||||
): DynamicRoomList
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -192,7 +192,6 @@ class RustMatrixClient(
|
|||
sessionDispatcher = sessionDispatcher,
|
||||
roomListFactory = RoomListFactory(
|
||||
innerRoomListService = innerRoomListService,
|
||||
sessionCoroutineScope = sessionCoroutineScope,
|
||||
analyticsService = analyticsService,
|
||||
),
|
||||
roomSyncSubscriber = roomSyncSubscriber,
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ private val ROOM_LIST_RUST_FILTERS = listOf(
|
|||
|
||||
internal class RoomListFactory(
|
||||
private val innerRoomListService: RoomListService,
|
||||
private val sessionCoroutineScope: CoroutineScope,
|
||||
private val analyticsService: AnalyticsService,
|
||||
) {
|
||||
private val roomSummaryFactory: RoomSummaryFactory = RoomSummaryFactory()
|
||||
|
|
@ -49,7 +48,7 @@ internal class RoomListFactory(
|
|||
fun createRoomList(
|
||||
pageSize: Int,
|
||||
coroutineContext: CoroutineContext,
|
||||
coroutineScope: CoroutineScope = sessionCoroutineScope,
|
||||
coroutineScope: CoroutineScope,
|
||||
initialFilter: RoomListFilter = RoomListFilter.all(),
|
||||
innerProvider: suspend () -> InnerRoomList
|
||||
): DynamicRoomList {
|
||||
|
|
|
|||
|
|
@ -35,17 +35,19 @@ internal class RustRoomListService(
|
|||
private val sessionDispatcher: CoroutineDispatcher,
|
||||
private val roomListFactory: RoomListFactory,
|
||||
private val roomSyncSubscriber: RoomSyncSubscriber,
|
||||
sessionCoroutineScope: CoroutineScope,
|
||||
private val sessionCoroutineScope: CoroutineScope,
|
||||
) : RoomListService {
|
||||
override fun createRoomList(
|
||||
pageSize: Int,
|
||||
initialFilter: RoomListFilter,
|
||||
source: RoomList.Source
|
||||
source: RoomList.Source,
|
||||
coroutineScope: CoroutineScope,
|
||||
): DynamicRoomList {
|
||||
return roomListFactory.createRoomList(
|
||||
pageSize = pageSize,
|
||||
initialFilter = initialFilter,
|
||||
coroutineContext = sessionDispatcher,
|
||||
coroutineScope = coroutineScope,
|
||||
) {
|
||||
when (source) {
|
||||
RoomList.Source.All -> innerRoomListService.allRooms()
|
||||
|
|
@ -60,6 +62,7 @@ internal class RustRoomListService(
|
|||
override val allRooms: DynamicRoomList = roomListFactory.createRoomList(
|
||||
pageSize = DEFAULT_PAGE_SIZE,
|
||||
coroutineContext = sessionDispatcher,
|
||||
coroutineScope = sessionCoroutineScope,
|
||||
) {
|
||||
innerRoomListService.allRooms()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@ class RoomListFactoryTest {
|
|||
fun `createRoomList should work`() = runTest {
|
||||
val sut = RoomListFactory(
|
||||
innerRoomListService = FakeFfiRoomListService(),
|
||||
sessionCoroutineScope = backgroundScope,
|
||||
analyticsService = FakeAnalyticsService(),
|
||||
)
|
||||
sut.createRoomList(
|
||||
pageSize = 10,
|
||||
coroutineContext = EmptyCoroutineContext,
|
||||
coroutineScope = backgroundScope,
|
||||
) {
|
||||
FakeFfiRoomList()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ private fun TestScope.createRustRoomListService(
|
|||
sessionDispatcher = StandardTestDispatcher(testScheduler),
|
||||
roomListFactory = RoomListFactory(
|
||||
innerRoomListService = roomListService,
|
||||
sessionCoroutineScope = backgroundScope,
|
||||
analyticsService = FakeAnalyticsService(),
|
||||
),
|
||||
roomSyncSubscriber = RoomSyncSubscriber(
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import io.element.android.libraries.matrix.api.roomlist.RoomList
|
|||
import io.element.android.libraries.matrix.api.roomlist.RoomListFilter
|
||||
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
||||
import io.element.android.libraries.matrix.api.roomlist.RoomSummary
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
|
|
@ -44,7 +45,8 @@ class FakeRoomListService(
|
|||
override fun createRoomList(
|
||||
pageSize: Int,
|
||||
initialFilter: RoomListFilter,
|
||||
source: RoomList.Source
|
||||
source: RoomList.Source,
|
||||
coroutineScope: CoroutineScope,
|
||||
): DynamicRoomList {
|
||||
return when (source) {
|
||||
RoomList.Source.All -> allRooms
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue