mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 02:45:53 +03:00
providing a type for the NoFilter to avoid the ambiguity of the nullable param
This commit is contained in:
parent
1ba8d29333
commit
e8476882fc
8 changed files with 26 additions and 13 deletions
|
@ -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
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -46,6 +46,7 @@ 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.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 +236,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 +253,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()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ class UnreadMessagesSharedViewModel @AssistedInject constructor(
|
||||||
this.memberships = listOf(Membership.JOIN)
|
this.memberships = listOf(Membership.JOIN)
|
||||||
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
|
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
|
||||||
!vectorPreferences.prefSpacesShowAllRoomInHome()
|
!vectorPreferences.prefSpacesShowAllRoomInHome()
|
||||||
}
|
} ?: SpaceFilter.NoFilter
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
@ -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 }
|
||||||
|
@ -449,7 +450,7 @@ class RoomListSectionBuilder(
|
||||||
}
|
}
|
||||||
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
|
||||||
|
|
|
@ -39,6 +39,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
|
||||||
|
@ -121,15 +122,15 @@ class HomeRoomListViewModel @AssistedInject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSpaceFilter(selectedSpaceId: String?, strategy: RoomListViewModel.SpaceFilterStrategy): SpaceFilter? {
|
private fun getSpaceFilter(selectedSpaceId: String?, strategy: RoomListViewModel.SpaceFilterStrategy): SpaceFilter {
|
||||||
return when (strategy) {
|
return when (strategy) {
|
||||||
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> {
|
RoomListViewModel.SpaceFilterStrategy.ORPHANS_IF_SPACE_NULL -> {
|
||||||
selectedSpaceId.toActiveSpaceOrOrphanRooms()
|
selectedSpaceId.toActiveSpaceOrOrphanRooms()
|
||||||
}
|
}
|
||||||
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> {
|
RoomListViewModel.SpaceFilterStrategy.ALL_IF_SPACE_NULL -> {
|
||||||
selectedSpaceId?.let { SpaceFilter.ActiveSpace(it) }
|
selectedSpaceId.toActiveSpaceOrNoFilter()
|
||||||
}
|
}
|
||||||
RoomListViewModel.SpaceFilterStrategy.NONE -> null
|
RoomListViewModel.SpaceFilterStrategy.NONE -> SpaceFilter.NoFilter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@ class SpaceListViewModel @AssistedInject constructor(
|
||||||
this.memberships = listOf(Membership.JOIN)
|
this.memberships = listOf(Membership.JOIN)
|
||||||
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
|
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
|
||||||
!vectorPreferences.prefSpacesShowAllRoomInHome()
|
!vectorPreferences.prefSpacesShowAllRoomInHome()
|
||||||
}
|
} ?: SpaceFilter.NoFilter
|
||||||
}, sortOrder = RoomSortOrder.NONE
|
}, sortOrder = RoomSortOrder.NONE
|
||||||
).asFlow()
|
).asFlow()
|
||||||
.sample(300)
|
.sample(300)
|
||||||
|
@ -117,7 +117,7 @@ class SpaceListViewModel @AssistedInject constructor(
|
||||||
this.memberships = listOf(Membership.JOIN)
|
this.memberships = listOf(Membership.JOIN)
|
||||||
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
|
this.spaceFilter = SpaceFilter.OrphanRooms.takeIf {
|
||||||
!vectorPreferences.prefSpacesShowAllRoomInHome()
|
!vectorPreferences.prefSpacesShowAllRoomInHome()
|
||||||
}
|
} ?: SpaceFilter.NoFilter
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
val counts = RoomAggregateNotificationCount(
|
val counts = RoomAggregateNotificationCount(
|
||||||
|
|
Loading…
Reference in a new issue