From 14666998e1955e7db0fc82d3e4e7a26e46e449a0 Mon Sep 17 00:00:00 2001 From: David Langley Date: Thu, 14 Sep 2023 20:31:34 +0100 Subject: [PATCH] Update RoomListDataSource.kt --- .../impl/datasource/RoomListDataSource.kt | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/datasource/RoomListDataSource.kt b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/datasource/RoomListDataSource.kt index 2cf28a6913..ac0b3ca568 100644 --- a/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/datasource/RoomListDataSource.kt +++ b/features/roomlist/impl/src/main/kotlin/io/element/android/features/roomlist/impl/datasource/RoomListDataSource.kt @@ -35,6 +35,7 @@ import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine @@ -52,17 +53,13 @@ class RoomListDataSource @Inject constructor( private val lastMessageTimestampFormatter: LastMessageTimestampFormatter, private val roomLastMessageFormatter: RoomLastMessageFormatter, private val coroutineDispatchers: CoroutineDispatchers, - notificationSettingsService: NotificationSettingsService, - appScope: CoroutineScope, + private val notificationSettingsService: NotificationSettingsService, + private val appScope: CoroutineScope, ) { init { - notificationSettingsService.notificationSettingsChangeFlow - .debounce(0.5.seconds) - .onEach { - roomListService.rebuildRoomSummaries() - } - .launchIn(appScope) + observerNotificationSettings() } + private val _filter = MutableStateFlow("") private val _allRooms = MutableStateFlow>(persistentListOf()) private val _filteredRooms = MutableStateFlow>(persistentListOf()) @@ -105,6 +102,16 @@ class RoomListDataSource @Inject constructor( val allRooms: StateFlow> = _allRooms val filteredRooms: StateFlow> = _filteredRooms + @OptIn(FlowPreview::class) + private fun observerNotificationSettings() { + notificationSettingsService.notificationSettingsChangeFlow + .debounce(0.5.seconds) + .onEach { + roomListService.rebuildRoomSummaries() + } + .launchIn(appScope) + } + private suspend fun replaceWith(roomSummaries: List) = withContext(coroutineDispatchers.computation) { lock.withLock { diffCacheUpdater.updateWith(roomSummaries)