Merge remote-tracking branch 'origin/feature/nfe/app_layout_hide_filters_for_space' into feature/eric/new-layout-labs

This commit is contained in:
ericdecanini 2022-09-06 14:46:12 +02:00
commit 91b4918526

View file

@ -40,6 +40,7 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
@ -202,22 +203,36 @@ class HomeRoomListViewModel @AssistedInject constructor(
private fun getFiltersDataFlow(): SharedFlow<Optional<List<HomeRoomFilter>>> { private fun getFiltersDataFlow(): SharedFlow<Optional<List<HomeRoomFilter>>> {
val flow = MutableSharedFlow<Optional<List<HomeRoomFilter>>>(replay = 1) val flow = MutableSharedFlow<Optional<List<HomeRoomFilter>>>(replay = 1)
val favouritesFlow = session.flow() val spaceFLow = spaceStateHandler.getSelectedSpaceFlow()
.distinctUntilChanged()
.onStart {
emit(spaceStateHandler.getCurrentSpace().toOption())
}
val favouritesFlow =
spaceFLow.flatMapLatest { selectedSpace ->
session.flow()
.liveRoomSummaries( .liveRoomSummaries(
RoomSummaryQueryParams.Builder().also { builder -> RoomSummaryQueryParams.Builder().also { builder ->
builder.spaceFilter = selectedSpace.orNull()?.roomId.toActiveSpaceOrNoFilter()
builder.roomTagQueryFilter = RoomTagQueryFilter(true, null, null) builder.roomTagQueryFilter = RoomTagQueryFilter(true, null, null)
}.build() }.build()
) )
}
.map { it.isNotEmpty() } .map { it.isNotEmpty() }
.distinctUntilChanged() .distinctUntilChanged()
val dmsFLow = session.flow() val dmsFLow =
spaceFLow.flatMapLatest { selectedSpace ->
session.flow()
.liveRoomSummaries( .liveRoomSummaries(
RoomSummaryQueryParams.Builder().also { builder -> RoomSummaryQueryParams.Builder().also { builder ->
builder.spaceFilter = selectedSpace.orNull()?.roomId.toActiveSpaceOrNoFilter()
builder.memberships = listOf(Membership.JOIN) builder.memberships = listOf(Membership.JOIN)
builder.roomCategoryFilter = RoomCategoryFilter.ONLY_DM builder.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
}.build() }.build()
) )
}
.map { it.isNotEmpty() } .map { it.isNotEmpty() }
.distinctUntilChanged() .distinctUntilChanged()