Rust : map the new filter api, will need more rework when branching the new ui later.

This commit is contained in:
ganfra 2024-02-08 20:46:27 +01:00
parent 5d055a5fd2
commit 2c24a48ed7
5 changed files with 99 additions and 38 deletions

View file

@ -28,29 +28,7 @@ import kotlinx.coroutines.flow.onEach
* It lets load rooms on demand and filter them.
*/
interface DynamicRoomList : RoomList {
sealed interface Filter {
/**
* No filter applied.
*/
data object All : Filter
/**
* Filter only the left rooms.
*/
data object AllNonLeft : Filter
/**
* Filter all rooms.
*/
data object None : Filter
/**
* Filter rooms by normalized room name.
*/
data class NormalizedMatchRoomName(val pattern: String) : Filter
}
val currentFilter: StateFlow<Filter>
val currentFilter: StateFlow<RoomListFilter>
val loadedPages: StateFlow<Int>
val pageSize: Int
@ -68,7 +46,7 @@ interface DynamicRoomList : RoomList {
* Update the filter to apply to the list.
* @param filter the filter to apply.
*/
suspend fun updateFilter(filter: Filter)
suspend fun updateFilter(filter: RoomListFilter)
}
/**

View file

@ -0,0 +1,56 @@
/*
* Copyright (c) 2024 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.matrix.api.roomlist
sealed interface RoomListFilter {
companion object {
fun all(vararg filters: RoomListFilter): RoomListFilter {
return All(filters.toList())
}
fun any(vararg filters: RoomListFilter): RoomListFilter {
return Any(filters.toList())
}
}
data class All(
val filters: List<RoomListFilter>
) : RoomListFilter
data class Any(
val filters: List<RoomListFilter>
) : RoomListFilter
data object NonLeft : RoomListFilter
data object Unread : RoomListFilter
sealed interface Category : RoomListFilter {
data object Group : Category
data object People : Category
}
data object None : RoomListFilter
data class NormalizedMatchRoomName(
val pattern: String
) : RoomListFilter
data class FuzzyMatchRoomName(
val pattern: String
) : RoomListFilter
}