mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 02:15:35 +03:00
Create extension String?.toActiveSpaceOrOrphanRooms()
to reduce noise.
This commit is contained in:
parent
d7a1ae3a00
commit
c071dc502e
3 changed files with 15 additions and 4 deletions
|
@ -36,3 +36,8 @@ sealed interface SpaceFilter {
|
|||
*/
|
||||
data class ExcludeSpace(val spaceId: String) : SpaceFilter
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a [SpaceFilter.ActiveSpace] if the String is not null, or [SpaceFilter.OrphanRooms].
|
||||
*/
|
||||
fun String?.toActiveSpaceOrOrphanRooms(): SpaceFilter = this?.let { SpaceFilter.ActiveSpace(it) } ?: SpaceFilter.OrphanRooms
|
||||
|
|
|
@ -47,6 +47,7 @@ import kotlinx.coroutines.flow.onEach
|
|||
import kotlinx.coroutines.launch
|
||||
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
||||
import org.matrix.android.sdk.api.query.SpaceFilter
|
||||
import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.crypto.NewSessionListener
|
||||
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
|
||||
|
@ -249,7 +250,7 @@ class HomeDetailViewModel @AssistedInject constructor(
|
|||
roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.INVITE)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||
spaceFilter = groupingMethod.spaceSummary?.roomId?.let { SpaceFilter.ActiveSpace(it) } ?: SpaceFilter.OrphanRooms
|
||||
spaceFilter = groupingMethod.toActiveSpaceOrOrphanRooms()
|
||||
}
|
||||
).size
|
||||
}
|
||||
|
@ -266,7 +267,7 @@ class HomeDetailViewModel @AssistedInject constructor(
|
|||
roomSummaryQueryParams {
|
||||
memberships = listOf(Membership.JOIN)
|
||||
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
|
||||
spaceFilter = groupingMethod.spaceSummary?.roomId?.let { SpaceFilter.ActiveSpace(it) } ?: SpaceFilter.OrphanRooms
|
||||
spaceFilter = groupingMethod.toActiveSpaceOrOrphanRooms()
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -287,4 +288,8 @@ class HomeDetailViewModel @AssistedInject constructor(
|
|||
}
|
||||
.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
private fun RoomGroupingMethod.BySpace.toActiveSpaceOrOrphanRooms(): SpaceFilter? {
|
||||
return spaceSummary?.roomId?.toActiveSpaceOrOrphanRooms()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.matrix.android.sdk.api.extensions.tryOrNull
|
|||
import org.matrix.android.sdk.api.query.RoomCategoryFilter
|
||||
import org.matrix.android.sdk.api.query.RoomTagQueryFilter
|
||||
import org.matrix.android.sdk.api.query.SpaceFilter
|
||||
import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import org.matrix.android.sdk.api.session.getRoomSummary
|
||||
import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams
|
||||
|
@ -370,7 +371,7 @@ class RoomListSectionBuilderSpace(
|
|||
activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater {
|
||||
override fun updateForSpaceId(roomId: String?) {
|
||||
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
|
||||
spaceFilter = roomId?.let { SpaceFilter.ActiveSpace(it) } ?: SpaceFilter.OrphanRooms
|
||||
spaceFilter = roomId?.toActiveSpaceOrOrphanRooms()
|
||||
)
|
||||
liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams }
|
||||
}
|
||||
|
@ -436,7 +437,7 @@ class RoomListSectionBuilderSpace(
|
|||
return when (spaceFilter) {
|
||||
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> {
|
||||
copy(
|
||||
spaceFilter = currentSpace?.let { SpaceFilter.ActiveSpace(it) } ?: SpaceFilter.OrphanRooms
|
||||
spaceFilter = currentSpace?.toActiveSpaceOrOrphanRooms()
|
||||
)
|
||||
}
|
||||
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> {
|
||||
|
|
Loading…
Reference in a new issue