Add API to control online search

This commit is contained in:
MM20
2024-01-28 21:35:36 +01:00
parent d7340c485b
commit 426473e397
20 changed files with 44 additions and 36 deletions
@@ -23,6 +23,7 @@ import kotlinx.coroutines.supervisorScope
interface SearchService {
fun search(
query: String,
allowNetwork: Boolean = false,
): Flow<SearchResults>
}
@@ -42,6 +43,7 @@ internal class SearchServiceImpl(
override fun search(
query: String,
allowNetwork: Boolean,
): Flow<SearchResults> = channelFlow {
val results = MutableStateFlow(SearchResults())
supervisorScope {
@@ -54,7 +56,7 @@ internal class SearchServiceImpl(
}
}
launch {
appRepository.search(query)
appRepository.search(query, allowNetwork)
.withCustomLabels(customAttributesRepository)
.collectLatest { r ->
results.update {
@@ -63,7 +65,7 @@ internal class SearchServiceImpl(
}
}
launch {
appShortcutRepository.search(query)
appShortcutRepository.search(query, allowNetwork)
.withCustomLabels(customAttributesRepository)
.collectLatest { r ->
results.update {
@@ -72,7 +74,7 @@ internal class SearchServiceImpl(
}
}
launch {
contactRepository.search(query)
contactRepository.search(query, allowNetwork)
.withCustomLabels(customAttributesRepository)
.collectLatest { r ->
results.update {
@@ -81,7 +83,7 @@ internal class SearchServiceImpl(
}
}
launch {
calendarRepository.search(query)
calendarRepository.search(query, allowNetwork)
.withCustomLabels(customAttributesRepository)
.collectLatest { r ->
results.update {
@@ -107,7 +109,7 @@ internal class SearchServiceImpl(
}
}
launch {
websiteRepository.search(query)
websiteRepository.search(query, allowNetwork)
.withCustomLabels(customAttributesRepository)
.collectLatest { r ->
results.update {
@@ -117,7 +119,7 @@ internal class SearchServiceImpl(
}
launch {
delay(750)
articleRepository.search(query)
articleRepository.search(query, allowNetwork)
.withCustomLabels(customAttributesRepository)
.collectLatest { r ->
results.update {
@@ -128,6 +130,7 @@ internal class SearchServiceImpl(
launch {
fileRepository.search(
query,
allowNetwork
)
.withCustomLabels(customAttributesRepository)
.collectLatest { r ->