mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-04 10:32:34 +00:00
Room list : debounce subscribe to visible rooms.
This commit is contained in:
+6
-2
@@ -61,7 +61,7 @@ import kotlinx.collections.immutable.toPersistentList
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.collect
|
import kotlinx.coroutines.flow.collect
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
@@ -73,6 +73,7 @@ import kotlinx.coroutines.launch
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
private const val EXTENDED_RANGE_SIZE = 40
|
private const val EXTENDED_RANGE_SIZE = 40
|
||||||
|
private const val SUBSCRIBE_TO_VISIBLE_ROOMS_DEBOUNCE_IN_MILLIS = 300L
|
||||||
|
|
||||||
class RoomListPresenter @Inject constructor(
|
class RoomListPresenter @Inject constructor(
|
||||||
private val client: MatrixClient,
|
private val client: MatrixClient,
|
||||||
@@ -301,7 +302,10 @@ class RoomListPresenter @Inject constructor(
|
|||||||
private var currentUpdateVisibleRangeJob: Job? = null
|
private var currentUpdateVisibleRangeJob: Job? = null
|
||||||
private fun CoroutineScope.updateVisibleRange(range: IntRange) {
|
private fun CoroutineScope.updateVisibleRange(range: IntRange) {
|
||||||
currentUpdateVisibleRangeJob?.cancel()
|
currentUpdateVisibleRangeJob?.cancel()
|
||||||
currentUpdateVisibleRangeJob = launch(SupervisorJob()) {
|
currentUpdateVisibleRangeJob = launch {
|
||||||
|
// Debounce the subscription to avoid subscribing to too many rooms
|
||||||
|
delay(SUBSCRIBE_TO_VISIBLE_ROOMS_DEBOUNCE_IN_MILLIS)
|
||||||
|
|
||||||
if (range.isEmpty()) return@launch
|
if (range.isEmpty()) return@launch
|
||||||
val currentRoomList = roomListDataSource.allRooms.first()
|
val currentRoomList = roomListDataSource.allRooms.first()
|
||||||
// Use extended range to 'prefetch' the next rooms info
|
// Use extended range to 'prefetch' the next rooms info
|
||||||
|
|||||||
+1
-5
@@ -53,11 +53,7 @@ internal class RustRoomListService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun subscribeToVisibleRooms(roomIds: List<RoomId>) {
|
override suspend fun subscribeToVisibleRooms(roomIds: List<RoomId>) {
|
||||||
val toSubscribe = roomIds.filterNot { roomSyncSubscriber.isSubscribedTo(it) }
|
roomSyncSubscriber.batchSubscribe(roomIds)
|
||||||
if (toSubscribe.isNotEmpty()) {
|
|
||||||
Timber.d("Subscribe to ${toSubscribe.size} rooms: $toSubscribe")
|
|
||||||
roomSyncSubscriber.batchSubscribe(toSubscribe)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override val allRooms: DynamicRoomList = roomListFactory.createRoomList(
|
override val allRooms: DynamicRoomList = roomListFactory.createRoomList(
|
||||||
|
|||||||
Reference in New Issue
Block a user