RoomList : rework how search is done to prepare for later filtering

This commit is contained in:
ganfra 2024-02-16 19:22:06 +01:00
parent 2bed671c00
commit ebb07de8a4
25 changed files with 512 additions and 196 deletions

View file

@ -33,6 +33,11 @@ interface RoomList {
data class Loaded(val numberOfRooms: Int) : LoadingState
}
enum class Source {
All,
Invites,
}
/**
* The list of room summaries as a flow.
*/

View file

@ -18,38 +18,68 @@ package io.element.android.libraries.matrix.api.roomlist
sealed interface RoomListFilter {
companion object {
/**
* Create a filter that matches all the given filters.
*/
fun all(vararg filters: RoomListFilter): RoomListFilter {
return All(filters.toList())
}
/**
* Create a filter that matches any of the given filters.
*/
fun any(vararg filters: RoomListFilter): RoomListFilter {
return Any(filters.toList())
}
}
/**
* A filter that matches all the given filters.
*/
data class All(
val filters: List<RoomListFilter>
) : RoomListFilter
/**
* A filter that matches any of the given filters.
*/
data class Any(
val filters: List<RoomListFilter>
) : RoomListFilter
/**
* A filter that matches rooms that are not left.
*/
data object NonLeft : RoomListFilter
/**
* A filter that matches rooms that are unread.
*/
data object Unread : RoomListFilter
/**
* A filter that matches either Group or People rooms.
*/
sealed interface Category : RoomListFilter {
data object Group : Category
data object People : Category
}
/**
* A filter that matches no room.
*/
data object None : RoomListFilter
/**
* A filter that matches rooms with a name using a normalized match.
*/
data class NormalizedMatchRoomName(
val pattern: String
) : RoomListFilter
/**
* A filter that matches rooms with a name using a fuzzy match.
*/
data class FuzzyMatchRoomName(
val pattern: String
) : RoomListFilter

View file

@ -17,6 +17,7 @@
package io.element.android.libraries.matrix.api.roomlist
import androidx.compose.runtime.Immutable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow
/**
@ -39,6 +40,20 @@ interface RoomListService {
data object Hide : SyncIndicator
}
/**
* Creates a room list that can be used to load more rooms and filter them dynamically.
* @param coroutineScope the scope to use for the room list. When the scope will be closed, the room list will be closed too.
* @param pageSize the number of rooms to load at once.
* @param initialFilter the initial filter to apply to the rooms.
* @param source the source of the rooms, either all rooms or invites.
*/
fun createRoomList(
coroutineScope: CoroutineScope,
pageSize: Int,
initialFilter: RoomListFilter,
source: RoomList.Source,
): DynamicRoomList
/**
* returns a [DynamicRoomList] object of all rooms we want to display.
* This will exclude some rooms like the invites, or spaces.