Merge pull request #6666 from vector-im/feature/adm/missing-space-rooms

`Home` always showing all rooms
This commit is contained in:
Adam Brown 2022-07-28 12:10:36 +01:00 committed by GitHub
commit b409431b0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 39 additions and 34 deletions

1
changelog.d/6665.bugfix Normal file
View File

@ -0,0 +1 @@
Fixes the room list not taking into account the Show all rooms in Home preference

1
changelog.d/6666.sdk Normal file
View File

@ -0,0 +1 @@
SDK - The SpaceFilter is query parameter is no longer nullable, use SpaceFilter.NoFilter instead

View File

@ -35,9 +35,19 @@ sealed interface SpaceFilter {
* Used to get all the rooms that do not have the provided space in their parent hierarchy. * Used to get all the rooms that do not have the provided space in their parent hierarchy.
*/ */
data class ExcludeSpace(val spaceId: String) : SpaceFilter data class ExcludeSpace(val spaceId: String) : SpaceFilter
/**
* Used to apply no filtering to the space.
*/
object NoFilter : SpaceFilter
} }
/** /**
* Return a [SpaceFilter.ActiveSpace] if the String is not null, or [SpaceFilter.OrphanRooms]. * Return a [SpaceFilter.ActiveSpace] if the String is not null, or [SpaceFilter.OrphanRooms].
*/ */
fun String?.toActiveSpaceOrOrphanRooms(): SpaceFilter = this?.let { SpaceFilter.ActiveSpace(it) } ?: SpaceFilter.OrphanRooms fun String?.toActiveSpaceOrOrphanRooms(): SpaceFilter = this?.let { SpaceFilter.ActiveSpace(it) } ?: SpaceFilter.OrphanRooms
/**
* Return a [SpaceFilter.ActiveSpace] if the String is not null, or [SpaceFilter.NoFilter].
*/
fun String?.toActiveSpaceOrNoFilter(): SpaceFilter = this?.let { SpaceFilter.ActiveSpace(it) } ?: SpaceFilter.NoFilter

View File

@ -86,7 +86,7 @@ data class RoomSummaryQueryParams(
/** /**
* Used to filter room using the current space. * Used to filter room using the current space.
*/ */
val spaceFilter: SpaceFilter?, val spaceFilter: SpaceFilter,
) { ) {
/** /**
@ -101,7 +101,7 @@ data class RoomSummaryQueryParams(
var roomTagQueryFilter: RoomTagQueryFilter? = null var roomTagQueryFilter: RoomTagQueryFilter? = null
var excludeType: List<String?>? = listOf(RoomType.SPACE) var excludeType: List<String?>? = listOf(RoomType.SPACE)
var includeType: List<String?>? = null var includeType: List<String?>? = null
var spaceFilter: SpaceFilter? = null var spaceFilter: SpaceFilter = SpaceFilter.NoFilter
fun build() = RoomSummaryQueryParams( fun build() = RoomSummaryQueryParams(
displayName = displayName, displayName = displayName,

View File

@ -317,7 +317,7 @@ internal class RoomSummaryDataSource @Inject constructor(
is SpaceFilter.ExcludeSpace -> { is SpaceFilter.ExcludeSpace -> {
query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.spaceFilter.spaceId) query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.spaceFilter.spaceId)
} }
null -> Unit // nop SpaceFilter.NoFilter -> Unit // nop
} }
return query return query

View File

@ -45,7 +45,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter import org.matrix.android.sdk.api.query.toActiveSpaceOrNoFilter
import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.crypto.NewSessionListener import org.matrix.android.sdk.api.session.crypto.NewSessionListener
@ -235,7 +235,7 @@ class HomeDetailViewModel @AssistedInject constructor(
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.INVITE) memberships = listOf(Membership.INVITE)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM roomCategoryFilter = RoomCategoryFilter.ONLY_DM
spaceFilter = activeSpaceRoomId?.let { SpaceFilter.ActiveSpace(it) } spaceFilter = activeSpaceRoomId.toActiveSpaceOrNoFilter()
} }
).size ).size
@ -252,7 +252,7 @@ class HomeDetailViewModel @AssistedInject constructor(
roomSummaryQueryParams { roomSummaryQueryParams {
memberships = listOf(Membership.JOIN) memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM roomCategoryFilter = RoomCategoryFilter.ONLY_DM
spaceFilter = activeSpaceRoomId?.let { SpaceFilter.ActiveSpace(it) } spaceFilter = activeSpaceRoomId.toActiveSpaceOrNoFilter()
} }
) )

View File

@ -142,8 +142,9 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(
val totalCount = roomService.getNotificationCountForRooms( val totalCount = roomService.getNotificationCountForRooms(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf { this.spaceFilter = when {
!vectorPreferences.prefSpacesShowAllRoomInHome() vectorPreferences.prefSpacesShowAllRoomInHome() -> SpaceFilter.NoFilter
else -> SpaceFilter.OrphanRooms
} }
} }
) )

View File

@ -45,6 +45,7 @@ import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.query.RoomCategoryFilter import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.RoomTagQueryFilter import org.matrix.android.sdk.api.query.RoomTagQueryFilter
import org.matrix.android.sdk.api.query.SpaceFilter import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.query.toActiveSpaceOrNoFilter
import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.getRoomSummary
@ -378,7 +379,7 @@ class RoomListSectionBuilder(
activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater { activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater {
override fun updateForSpaceId(roomId: String?) { override fun updateForSpaceId(roomId: String?) {
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
spaceFilter = roomId?.toActiveSpaceOrOrphanRooms() spaceFilter = roomId.toActiveSpaceOrOrphanRooms()
) )
liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams } liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams }
} }
@ -393,7 +394,7 @@ class RoomListSectionBuilder(
) )
} else { } else {
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
spaceFilter = null spaceFilter = SpaceFilter.NoFilter
) )
} }
liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams } liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams }
@ -444,12 +445,12 @@ class RoomListSectionBuilder(
return when (spaceFilter) { return when (spaceFilter) {
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> { RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> {
copy( copy(
spaceFilter = currentSpace?.toActiveSpaceOrOrphanRooms() spaceFilter = currentSpace.toActiveSpaceOrOrphanRooms()
) )
} }
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> { RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> {
copy( copy(
spaceFilter = currentSpace?.let { SpaceFilter.ActiveSpace(it) } spaceFilter = currentSpace.toActiveSpaceOrNoFilter()
) )
} }
RoomListViewModel.SpaceFilterStrategy.NONE -> this RoomListViewModel.SpaceFilterStrategy.NONE -> this

View File

@ -27,7 +27,6 @@ import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.StateView import im.vector.app.core.platform.StateView
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.home.room.list.RoomListViewModel
import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorPreferences
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
@ -39,6 +38,7 @@ import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.query.SpaceFilter import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.query.toActiveSpaceOrNoFilter
import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms import org.matrix.android.sdk.api.query.toActiveSpaceOrOrphanRooms
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.getRoom import org.matrix.android.sdk.api.session.getRoom
@ -106,13 +106,8 @@ class HomeRoomListViewModel @AssistedInject constructor(
} }
.onEach { selectedSpaceOption -> .onEach { selectedSpaceOption ->
val selectedSpace = selectedSpaceOption.orNull() val selectedSpace = selectedSpaceOption.orNull()
val strategy = if (!vectorPreferences.prefSpacesShowAllRoomInHome()) {
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL
} else {
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL
}
filteredPagedRoomSummariesLive.queryParams = filteredPagedRoomSummariesLive.queryParams.copy( filteredPagedRoomSummariesLive.queryParams = filteredPagedRoomSummariesLive.queryParams.copy(
spaceFilter = getSpaceFilter(selectedSpaceId = selectedSpace?.roomId, strategy) spaceFilter = getSpaceFilter(selectedSpaceId = selectedSpace?.roomId)
) )
}.launchIn(viewModelScope) }.launchIn(viewModelScope)
@ -121,15 +116,10 @@ class HomeRoomListViewModel @AssistedInject constructor(
) )
} }
private fun getSpaceFilter(selectedSpaceId: String?, strategy: RoomListViewModel.SpaceFilterStrategy): SpaceFilter? { private fun getSpaceFilter(selectedSpaceId: String?): SpaceFilter {
return when (strategy) { return when {
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> { vectorPreferences.prefSpacesShowAllRoomInHome() -> selectedSpaceId.toActiveSpaceOrNoFilter()
selectedSpaceId?.toActiveSpaceOrOrphanRooms() else -> selectedSpaceId.toActiveSpaceOrOrphanRooms()
}
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> {
selectedSpaceId?.let { SpaceFilter.ActiveSpace(it) }
}
RoomListViewModel.SpaceFilterStrategy.NONE -> null
} }
} }

View File

@ -98,9 +98,7 @@ class SpaceListViewModel @AssistedInject constructor(
session.roomService().getPagedRoomSummariesLive( session.roomService().getPagedRoomSummariesLive(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf { this.spaceFilter = roomsInSpaceFilter()
!vectorPreferences.prefSpacesShowAllRoomInHome()
}
}, sortOrder = RoomSortOrder.NONE }, sortOrder = RoomSortOrder.NONE
).asFlow() ).asFlow()
.sample(300) .sample(300)
@ -115,9 +113,7 @@ class SpaceListViewModel @AssistedInject constructor(
val totalCount = session.roomService().getNotificationCountForRooms( val totalCount = session.roomService().getNotificationCountForRooms(
roomSummaryQueryParams { roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN) this.memberships = listOf(Membership.JOIN)
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf { this.spaceFilter = roomsInSpaceFilter()
!vectorPreferences.prefSpacesShowAllRoomInHome()
}
} }
) )
val counts = RoomAggregateNotificationCount( val counts = RoomAggregateNotificationCount(
@ -134,6 +130,11 @@ class SpaceListViewModel @AssistedInject constructor(
.launchIn(viewModelScope) .launchIn(viewModelScope)
} }
private fun roomsInSpaceFilter() = when {
vectorPreferences.prefSpacesShowAllRoomInHome() -> SpaceFilter.NoFilter
else -> SpaceFilter.OrphanRooms
}
override fun handle(action: SpaceListAction) { override fun handle(action: SpaceListAction) {
when (action) { when (action) {
is SpaceListAction.SelectSpace -> handleSelectSpace(action) is SpaceListAction.SelectSpace -> handleSelectSpace(action)