diff --git a/changelog.d/6665.bugfix b/changelog.d/6665.bugfix new file mode 100644 index 0000000000..678b995fcf --- /dev/null +++ b/changelog.d/6665.bugfix @@ -0,0 +1 @@ +Fixes the room list not taking into account the Show all rooms in Home preference diff --git a/changelog.d/6666.sdk b/changelog.d/6666.sdk new file mode 100644 index 0000000000..ad1cea8dc9 --- /dev/null +++ b/changelog.d/6666.sdk @@ -0,0 +1 @@ +SDK - The SpaceFilter is query parameter is no longer nullable, use SpaceFilter.NoFilter instead diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/query/SpaceFilter.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/query/SpaceFilter.kt index 6383412ffb..ccefd5855f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/query/SpaceFilter.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/query/SpaceFilter.kt @@ -35,9 +35,19 @@ sealed interface SpaceFilter { * Used to get all the rooms that do not have the provided space in their parent hierarchy. */ 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]. */ 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 diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt index 00c6da00b7..60963ef25a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomSummaryQueryParams.kt @@ -86,7 +86,7 @@ data class RoomSummaryQueryParams( /** * 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 excludeType: List? = listOf(RoomType.SPACE) var includeType: List? = null - var spaceFilter: SpaceFilter? = null + var spaceFilter: SpaceFilter = SpaceFilter.NoFilter fun build() = RoomSummaryQueryParams( displayName = displayName, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt index 9d14ebffdd..82fc94df7c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/summary/RoomSummaryDataSource.kt @@ -317,7 +317,7 @@ internal class RoomSummaryDataSource @Inject constructor( is SpaceFilter.ExcludeSpace -> { query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.spaceFilter.spaceId) } - null -> Unit // nop + SpaceFilter.NoFilter -> Unit // nop } return query diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt index 787458993f..4be30f753b 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailViewModel.kt @@ -45,7 +45,7 @@ import kotlinx.coroutines.flow.launchIn 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.toActiveSpaceOrNoFilter 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 @@ -235,7 +235,7 @@ class HomeDetailViewModel @AssistedInject constructor( roomSummaryQueryParams { memberships = listOf(Membership.INVITE) roomCategoryFilter = RoomCategoryFilter.ONLY_DM - spaceFilter = activeSpaceRoomId?.let { SpaceFilter.ActiveSpace(it) } + spaceFilter = activeSpaceRoomId.toActiveSpaceOrNoFilter() } ).size @@ -252,7 +252,7 @@ class HomeDetailViewModel @AssistedInject constructor( roomSummaryQueryParams { memberships = listOf(Membership.JOIN) roomCategoryFilter = RoomCategoryFilter.ONLY_DM - spaceFilter = activeSpaceRoomId?.let { SpaceFilter.ActiveSpace(it) } + spaceFilter = activeSpaceRoomId.toActiveSpaceOrNoFilter() } ) diff --git a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt index f2e6b7e064..5f4782123c 100644 --- a/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/UnreadMessagesSharedViewModel.kt @@ -142,8 +142,9 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor( val totalCount = roomService.getNotificationCountForRooms( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) - this.spaceFilter = SpaceFilter.OrphanRooms.takeIf { - !vectorPreferences.prefSpacesShowAllRoomInHome() + this.spaceFilter = when { + vectorPreferences.prefSpacesShowAllRoomInHome() -> SpaceFilter.NoFilter + else -> SpaceFilter.OrphanRooms } } ) diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt index f929366a5e..b2187fb365 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilder.kt @@ -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.RoomTagQueryFilter 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.session.Session import org.matrix.android.sdk.api.session.getRoomSummary @@ -378,7 +379,7 @@ class RoomListSectionBuilder( activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater { override fun updateForSpaceId(roomId: String?) { filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( - spaceFilter = roomId?.toActiveSpaceOrOrphanRooms() + spaceFilter = roomId.toActiveSpaceOrOrphanRooms() ) liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams } } @@ -393,7 +394,7 @@ class RoomListSectionBuilder( ) } else { filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy( - spaceFilter = null + spaceFilter = SpaceFilter.NoFilter ) } liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams } @@ -444,12 +445,12 @@ class RoomListSectionBuilder( return when (spaceFilter) { RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> { copy( - spaceFilter = currentSpace?.toActiveSpaceOrOrphanRooms() + spaceFilter = currentSpace.toActiveSpaceOrOrphanRooms() ) } RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> { copy( - spaceFilter = currentSpace?.let { SpaceFilter.ActiveSpace(it) } + spaceFilter = currentSpace.toActiveSpaceOrNoFilter() ) } RoomListViewModel.SpaceFilterStrategy.NONE -> this diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt index 3226ed24f2..7b257b1d1c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/home/HomeRoomListViewModel.kt @@ -27,7 +27,6 @@ import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.platform.StateView import im.vector.app.core.platform.VectorViewModel -import im.vector.app.features.home.room.list.RoomListViewModel import im.vector.app.features.settings.VectorPreferences import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableSharedFlow @@ -39,6 +38,7 @@ import kotlinx.coroutines.flow.onStart import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.orFalse 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.session.Session import org.matrix.android.sdk.api.session.getRoom @@ -106,13 +106,8 @@ class HomeRoomListViewModel @AssistedInject constructor( } .onEach { selectedSpaceOption -> 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( - spaceFilter = getSpaceFilter(selectedSpaceId = selectedSpace?.roomId, strategy) + spaceFilter = getSpaceFilter(selectedSpaceId = selectedSpace?.roomId) ) }.launchIn(viewModelScope) @@ -121,15 +116,10 @@ class HomeRoomListViewModel @AssistedInject constructor( ) } - private fun getSpaceFilter(selectedSpaceId: String?, strategy: RoomListViewModel.SpaceFilterStrategy): SpaceFilter? { - return when (strategy) { - RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> { - selectedSpaceId?.toActiveSpaceOrOrphanRooms() - } - RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> { - selectedSpaceId?.let { SpaceFilter.ActiveSpace(it) } - } - RoomListViewModel.SpaceFilterStrategy.NONE -> null + private fun getSpaceFilter(selectedSpaceId: String?): SpaceFilter { + return when { + vectorPreferences.prefSpacesShowAllRoomInHome() -> selectedSpaceId.toActiveSpaceOrNoFilter() + else -> selectedSpaceId.toActiveSpaceOrOrphanRooms() } } diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt index 3b2fb31b74..a104e9b170 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt @@ -98,9 +98,7 @@ class SpaceListViewModel @AssistedInject constructor( session.roomService().getPagedRoomSummariesLive( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) - this.spaceFilter = SpaceFilter.OrphanRooms.takeIf { - !vectorPreferences.prefSpacesShowAllRoomInHome() - } + this.spaceFilter = roomsInSpaceFilter() }, sortOrder = RoomSortOrder.NONE ).asFlow() .sample(300) @@ -115,9 +113,7 @@ class SpaceListViewModel @AssistedInject constructor( val totalCount = session.roomService().getNotificationCountForRooms( roomSummaryQueryParams { this.memberships = listOf(Membership.JOIN) - this.spaceFilter = SpaceFilter.OrphanRooms.takeIf { - !vectorPreferences.prefSpacesShowAllRoomInHome() - } + this.spaceFilter = roomsInSpaceFilter() } ) val counts = RoomAggregateNotificationCount( @@ -134,6 +130,11 @@ class SpaceListViewModel @AssistedInject constructor( .launchIn(viewModelScope) } + private fun roomsInSpaceFilter() = when { + vectorPreferences.prefSpacesShowAllRoomInHome() -> SpaceFilter.NoFilter + else -> SpaceFilter.OrphanRooms + } + override fun handle(action: SpaceListAction) { when (action) { is SpaceListAction.SelectSpace -> handleSelectSpace(action)