Rename UserSearchResults as UserSearchResultState
This commit is contained in:
parent
96302da97c
commit
9fcc50e08a
6 changed files with 49 additions and 27 deletions
|
|
@ -20,5 +20,5 @@ import kotlinx.coroutines.flow.Flow
|
|||
|
||||
interface UserRepository {
|
||||
|
||||
fun search(query: String): Flow<UserSearchResults>
|
||||
fun search(query: String): Flow<UserSearchResultState>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ data class UserSearchResult(
|
|||
val isUnresolved: Boolean = false,
|
||||
)
|
||||
|
||||
data class UserSearchResults(
|
||||
data class UserSearchResultState(
|
||||
val results: List<UserSearchResult>,
|
||||
val isFetchingSearchResults: Boolean = false,
|
||||
val isFetchingSearchResults: Boolean,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import io.element.android.libraries.matrix.api.user.MatrixUser
|
|||
import io.element.android.libraries.usersearch.api.UserListDataSource
|
||||
import io.element.android.libraries.usersearch.api.UserRepository
|
||||
import io.element.android.libraries.usersearch.api.UserSearchResult
|
||||
import io.element.android.libraries.usersearch.api.UserSearchResults
|
||||
import io.element.android.libraries.usersearch.api.UserSearchResultState
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
|
|
@ -37,7 +37,7 @@ class MatrixUserRepository @Inject constructor(
|
|||
private val dataSource: UserListDataSource
|
||||
) : UserRepository {
|
||||
|
||||
override fun search(query: String): Flow<UserSearchResults> = flow {
|
||||
override fun search(query: String): Flow<UserSearchResultState> = flow {
|
||||
val shouldQueryProfile = MatrixPatterns.isUserId(query) && !client.isMe(UserId(query))
|
||||
val shouldFetchSearchResults = query.length >= MINIMUM_SEARCH_LENGTH
|
||||
// If the search term is a MXID that's not ours, we'll show a 'fake' result for that user, then update it when we get search results.
|
||||
|
|
@ -47,7 +47,7 @@ class MatrixUserRepository @Inject constructor(
|
|||
null
|
||||
}
|
||||
if (shouldQueryProfile || shouldFetchSearchResults) {
|
||||
emit(UserSearchResults(isFetchingSearchResults = shouldFetchSearchResults, results = listOfNotNull(fakeSearchResult)))
|
||||
emit(UserSearchResultState(isFetchingSearchResults = shouldFetchSearchResults, results = listOfNotNull(fakeSearchResult)))
|
||||
}
|
||||
if (shouldFetchSearchResults) {
|
||||
val results = fetchSearchResults(query, shouldQueryProfile)
|
||||
|
|
@ -55,7 +55,7 @@ class MatrixUserRepository @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun fetchSearchResults(query: String, shouldQueryProfile: Boolean): UserSearchResults {
|
||||
private suspend fun fetchSearchResults(query: String, shouldQueryProfile: Boolean): UserSearchResultState {
|
||||
// Debounce
|
||||
delay(DEBOUNCE_TIME_MILLIS)
|
||||
val results = dataSource
|
||||
|
|
@ -73,7 +73,7 @@ class MatrixUserRepository @Inject constructor(
|
|||
?: UserSearchResult(MatrixUser(UserId(query)), isUnresolved = true))
|
||||
}
|
||||
|
||||
return UserSearchResults(results = results, isFetchingSearchResults = false)
|
||||
return UserSearchResultState(results = results, isFetchingSearchResults = false)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
package io.element.android.libraries.usersearch.test
|
||||
|
||||
import io.element.android.libraries.usersearch.api.UserRepository
|
||||
import io.element.android.libraries.usersearch.api.UserSearchResults
|
||||
import io.element.android.libraries.usersearch.api.UserSearchResultState
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
|
||||
|
|
@ -26,15 +26,15 @@ class FakeUserRepository : UserRepository {
|
|||
var providedQuery: String? = null
|
||||
private set
|
||||
|
||||
private val flow = MutableSharedFlow<UserSearchResults>()
|
||||
private val flow = MutableSharedFlow<UserSearchResultState>()
|
||||
|
||||
override fun search(query: String): Flow<UserSearchResults> {
|
||||
override fun search(query: String): Flow<UserSearchResultState> {
|
||||
providedQuery = query
|
||||
return flow
|
||||
}
|
||||
|
||||
suspend fun emitResult(result: UserSearchResults) {
|
||||
flow.emit(result)
|
||||
suspend fun emitState(state: UserSearchResultState) {
|
||||
flow.emit(state)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue