Rename ActiveSpaceFilter to SpaceFilter

This commit is contained in:
Benoit Marty 2022-05-24 16:26:16 +02:00 committed by Benoit Marty
parent 00809027c1
commit c7997edf9a
11 changed files with 45 additions and 45 deletions

View File

@ -29,8 +29,8 @@ import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.runners.MethodSorters
import org.matrix.android.sdk.InstrumentedTest
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toContent
@ -248,7 +248,7 @@ class SpaceHierarchyTest : InstrumentedTest {
Thread.sleep(6_000)
val orphansUpdate = session.roomService().getRoomSummaries(roomSummaryQueryParams {
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
spaceFilter = SpaceFilter.ActiveSpace(null)
})
assertEquals("Unexpected number of orphan rooms ${orphansUpdate.map { it.name }}", 2, orphansUpdate.size)
}

View File

@ -20,7 +20,7 @@ package org.matrix.android.sdk.api.query
* Filter to be used to do room queries.
* @see [org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams]
*/
sealed class ActiveSpaceFilter {
data class ActiveSpace(val currentSpaceId: String?) : ActiveSpaceFilter()
data class ExcludeSpace(val spaceId: String) : ActiveSpaceFilter()
sealed class SpaceFilter {
data class ActiveSpace(val currentSpaceId: String?) : SpaceFilter()
data class ExcludeSpace(val spaceId: String) : SpaceFilter()
}

View File

@ -16,10 +16,10 @@
package org.matrix.android.sdk.api.session.room
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.QueryStringValue
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.session.room.model.Membership
import org.matrix.android.sdk.api.session.room.model.RoomType
import org.matrix.android.sdk.api.session.space.SpaceSummaryQueryParams
@ -86,7 +86,7 @@ data class RoomSummaryQueryParams(
/**
* Used to filter room using the current space.
*/
val activeSpaceFilter: ActiveSpaceFilter?,
val spaceFilter: SpaceFilter?,
/**
* Used to filter room using the current group.
*/
@ -101,7 +101,7 @@ data class RoomSummaryQueryParams(
var roomTagQueryFilter: RoomTagQueryFilter? = null
var excludeType: List<String?>? = listOf(RoomType.SPACE)
var includeType: List<String?>? = null
var activeSpaceFilter: ActiveSpaceFilter? = null
var spaceFilter: SpaceFilter? = null
var activeGroupId: String? = null
fun build() = RoomSummaryQueryParams(
@ -112,7 +112,7 @@ data class RoomSummaryQueryParams(
roomTagQueryFilter = roomTagQueryFilter,
excludeType = excludeType,
includeType = includeType,
activeSpaceFilter = activeSpaceFilter,
spaceFilter = spaceFilter,
activeGroupId = activeGroupId
)
}

View File

@ -26,9 +26,9 @@ import com.zhuinden.monarchy.Monarchy
import io.realm.Realm
import io.realm.RealmQuery
import io.realm.kotlin.where
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.query.isNormalized
import org.matrix.android.sdk.api.session.room.ResultBoundaries
import org.matrix.android.sdk.api.session.room.RoomSortOrder
@ -300,21 +300,21 @@ internal class RoomSummaryDataSource @Inject constructor(
}
// Timber.w("VAL: activeSpaceId : ${queryParams.activeSpaceId}")
when (queryParams.activeSpaceFilter) {
is ActiveSpaceFilter.ActiveSpace -> {
when (queryParams.spaceFilter) {
is SpaceFilter.ActiveSpace -> {
// It's annoying but for now realm java does not support querying in primitive list :/
// https://github.com/realm/realm-java/issues/5361
if (queryParams.activeSpaceFilter.currentSpaceId == null) {
if (queryParams.spaceFilter.currentSpaceId == null) {
// orphan rooms
query.isNull(RoomSummaryEntityFields.FLATTEN_PARENT_IDS)
} else {
query.contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceFilter.currentSpaceId)
query.contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.spaceFilter.currentSpaceId)
}
}
is ActiveSpaceFilter.ExcludeSpace -> {
query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.activeSpaceFilter.spaceId)
is SpaceFilter.ExcludeSpace -> {
query.not().contains(RoomSummaryEntityFields.FLATTEN_PARENT_IDS, queryParams.spaceFilter.spaceId)
}
else -> {
else -> {
// nop
}
}

View File

@ -45,8 +45,8 @@ import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
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
@ -241,7 +241,7 @@ class HomeDetailViewModel @AssistedInject constructor(
roomSummaryQueryParams {
memberships = listOf(Membership.INVITE)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) }
spaceFilter = activeSpaceRoomId?.let { SpaceFilter.ActiveSpace(it) }
}
).size
@ -249,7 +249,7 @@ class HomeDetailViewModel @AssistedInject constructor(
roomSummaryQueryParams {
memberships = listOf(Membership.INVITE)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
spaceFilter = SpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
}
).size
}
@ -258,7 +258,7 @@ class HomeDetailViewModel @AssistedInject constructor(
roomSummaryQueryParams {
memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_DM
activeSpaceFilter = activeSpaceRoomId?.let { ActiveSpaceFilter.ActiveSpace(it) }
spaceFilter = activeSpaceRoomId?.let { SpaceFilter.ActiveSpace(it) }
}
)
@ -266,7 +266,7 @@ class HomeDetailViewModel @AssistedInject constructor(
roomSummaryQueryParams {
memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
spaceFilter = SpaceFilter.ActiveSpace(groupingMethod.spaceSummary?.roomId)
}
)

View File

@ -37,7 +37,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOn
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.RoomSortOrder
import org.matrix.android.sdk.api.session.room.model.Membership
@ -78,7 +78,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
roomService.getPagedRoomSummariesLive(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
this.spaceFilter = SpaceFilter.ActiveSpace(null)
}, sortOrder = RoomSortOrder.NONE
).asFlow()
.throttleFirst(300)
@ -86,7 +86,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
val counts = roomService.getNotificationCountForRooms(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
this.spaceFilter = SpaceFilter.ActiveSpace(null)
}
)
val invites = if (autoAcceptInvites.hideInvites) {
@ -95,7 +95,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
roomService.getRoomSummaries(
roomSummaryQueryParams {
this.memberships = listOf(Membership.INVITE)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null)
this.spaceFilter = SpaceFilter.ActiveSpace(null)
}
).size
}
@ -151,7 +151,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(@Assisted initia
val totalCount = roomService.getNotificationCountForRooms(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf {
this.spaceFilter = SpaceFilter.ActiveSpace(null).takeIf {
!vectorPreferences.prefSpacesShowAllRoomInHome()
}
}

View File

@ -43,9 +43,9 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
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.session.Session
import org.matrix.android.sdk.api.session.getRoomSummary
import org.matrix.android.sdk.api.session.room.RoomSummaryQueryParams
@ -370,7 +370,7 @@ class RoomListSectionBuilderSpace(
activeSpaceUpdaters.add(object : RoomListViewModel.ActiveSpaceQueryUpdater {
override fun updateForSpaceId(roomId: String?) {
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
spaceFilter = SpaceFilter.ActiveSpace(roomId)
)
liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams }
}
@ -381,11 +381,11 @@ class RoomListSectionBuilderSpace(
override fun updateForSpaceId(roomId: String?) {
if (roomId != null) {
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(roomId)
spaceFilter = SpaceFilter.ActiveSpace(roomId)
)
} else {
filteredPagedRoomSummariesLive.queryParams = roomQueryParams.copy(
activeSpaceFilter = null
spaceFilter = null
)
}
liveQueryParams.update { filteredPagedRoomSummariesLive.queryParams }
@ -436,17 +436,17 @@ class RoomListSectionBuilderSpace(
return when (spaceFilter) {
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> {
copy(
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
spaceFilter = SpaceFilter.ActiveSpace(currentSpace)
)
}
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> {
if (currentSpace == null) {
copy(
activeSpaceFilter = null
spaceFilter = null
)
} else {
copy(
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(currentSpace)
spaceFilter = SpaceFilter.ActiveSpace(currentSpace)
)
}
}

View File

@ -44,8 +44,8 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.sample
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.toContent
import org.matrix.android.sdk.api.session.events.model.toModel
@ -110,7 +110,7 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
session.roomService().getPagedRoomSummariesLive(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf {
this.spaceFilter = SpaceFilter.ActiveSpace(null).takeIf {
!vectorPreferences.prefSpacesShowAllRoomInHome()
}
}, sortOrder = RoomSortOrder.NONE
@ -127,7 +127,7 @@ class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: Spa
val totalCount = session.roomService().getNotificationCountForRooms(
roomSummaryQueryParams {
this.memberships = listOf(Membership.JOIN)
this.activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(null).takeIf {
this.spaceFilter = SpaceFilter.ActiveSpace(null).takeIf {
!vectorPreferences.prefSpacesShowAllRoomInHome()
}
}

View File

@ -34,8 +34,8 @@ import im.vector.app.features.session.coroutineScope
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.getRoom
@ -141,7 +141,7 @@ class SpaceMenuViewModel @AssistedInject constructor(
session.roomService().getRoomSummaries(
roomSummaryQueryParams {
excludeType = null
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(initialState.spaceId)
spaceFilter = SpaceFilter.ActiveSpace(initialState.spaceId)
memberships = listOf(Membership.JOIN)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
}

View File

@ -33,8 +33,8 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import okhttp3.internal.toImmutableList
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
@ -93,7 +93,7 @@ class SpaceLeaveAdvancedViewModel @AssistedInject constructor(
roomSummaryQueryParams {
includeType = null
memberships = listOf(Membership.JOIN)
activeSpaceFilter = ActiveSpaceFilter.ActiveSpace(initialState.spaceId)
spaceFilter = SpaceFilter.ActiveSpace(initialState.spaceId)
roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
}
)

View File

@ -35,9 +35,9 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.query.ActiveSpaceFilter
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.getRoomSummary
import org.matrix.android.sdk.api.session.room.RoomSortOrder
@ -72,7 +72,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
this.memberships = listOf(Membership.JOIN)
this.excludeType = null
this.includeType = listOf(RoomType.SPACE)
this.activeSpaceFilter = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId)
this.spaceFilter = SpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
},
pagedListConfig = PagedList.Config.Builder()
@ -98,7 +98,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
this.excludeType = listOf(RoomType.SPACE)
this.includeType = null
this.roomCategoryFilter = RoomCategoryFilter.ONLY_ROOMS
this.activeSpaceFilter = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId)
this.spaceFilter = SpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
},
pagedListConfig = PagedList.Config.Builder()
@ -124,7 +124,7 @@ class SpaceAddRoomsViewModel @AssistedInject constructor(
this.excludeType = listOf(RoomType.SPACE)
this.includeType = null
this.roomCategoryFilter = RoomCategoryFilter.ONLY_DM
this.activeSpaceFilter = ActiveSpaceFilter.ExcludeSpace(initialState.spaceId)
this.spaceFilter = SpaceFilter.ExcludeSpace(initialState.spaceId)
this.displayName = QueryStringValue.Contains(initialState.currentFilter, QueryStringValue.Case.INSENSITIVE)
},
pagedListConfig = PagedList.Config.Builder()