Update RoomListDataSource.kt
This commit is contained in:
parent
fc487ba9da
commit
14666998e1
1 changed files with 15 additions and 8 deletions
|
|
@ -35,6 +35,7 @@ import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.FlowPreview
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
|
|
@ -52,17 +53,13 @@ class RoomListDataSource @Inject constructor(
|
||||||
private val lastMessageTimestampFormatter: LastMessageTimestampFormatter,
|
private val lastMessageTimestampFormatter: LastMessageTimestampFormatter,
|
||||||
private val roomLastMessageFormatter: RoomLastMessageFormatter,
|
private val roomLastMessageFormatter: RoomLastMessageFormatter,
|
||||||
private val coroutineDispatchers: CoroutineDispatchers,
|
private val coroutineDispatchers: CoroutineDispatchers,
|
||||||
notificationSettingsService: NotificationSettingsService,
|
private val notificationSettingsService: NotificationSettingsService,
|
||||||
appScope: CoroutineScope,
|
private val appScope: CoroutineScope,
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
notificationSettingsService.notificationSettingsChangeFlow
|
observerNotificationSettings()
|
||||||
.debounce(0.5.seconds)
|
|
||||||
.onEach {
|
|
||||||
roomListService.rebuildRoomSummaries()
|
|
||||||
}
|
|
||||||
.launchIn(appScope)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val _filter = MutableStateFlow("")
|
private val _filter = MutableStateFlow("")
|
||||||
private val _allRooms = MutableStateFlow<ImmutableList<RoomListRoomSummary>>(persistentListOf())
|
private val _allRooms = MutableStateFlow<ImmutableList<RoomListRoomSummary>>(persistentListOf())
|
||||||
private val _filteredRooms = MutableStateFlow<ImmutableList<RoomListRoomSummary>>(persistentListOf())
|
private val _filteredRooms = MutableStateFlow<ImmutableList<RoomListRoomSummary>>(persistentListOf())
|
||||||
|
|
@ -105,6 +102,16 @@ class RoomListDataSource @Inject constructor(
|
||||||
val allRooms: StateFlow<ImmutableList<RoomListRoomSummary>> = _allRooms
|
val allRooms: StateFlow<ImmutableList<RoomListRoomSummary>> = _allRooms
|
||||||
val filteredRooms: StateFlow<ImmutableList<RoomListRoomSummary>> = _filteredRooms
|
val filteredRooms: StateFlow<ImmutableList<RoomListRoomSummary>> = _filteredRooms
|
||||||
|
|
||||||
|
@OptIn(FlowPreview::class)
|
||||||
|
private fun observerNotificationSettings() {
|
||||||
|
notificationSettingsService.notificationSettingsChangeFlow
|
||||||
|
.debounce(0.5.seconds)
|
||||||
|
.onEach {
|
||||||
|
roomListService.rebuildRoomSummaries()
|
||||||
|
}
|
||||||
|
.launchIn(appScope)
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun replaceWith(roomSummaries: List<RoomSummary>) = withContext(coroutineDispatchers.computation) {
|
private suspend fun replaceWith(roomSummaries: List<RoomSummary>) = withContext(coroutineDispatchers.computation) {
|
||||||
lock.withLock {
|
lock.withLock {
|
||||||
diffCacheUpdater.updateWith(roomSummaries)
|
diffCacheUpdater.updateWith(roomSummaries)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue