Skip to content

Commit 9cbfbf5

Browse files
Remove the need for stateflow for conversation list (#1776)
1 parent b63fdd6 commit 9cbfbf5

File tree

5 files changed

+601
-655
lines changed

5 files changed

+601
-655
lines changed

app/src/main/java/org/thoughtcrime/securesms/home/search/GlobalSearchViewModel.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import kotlinx.coroutines.Dispatchers
88
import kotlinx.coroutines.ExperimentalCoroutinesApi
99
import kotlinx.coroutines.flow.Flow
1010
import kotlinx.coroutines.flow.MutableStateFlow
11+
import kotlinx.coroutines.flow.SharedFlow
1112
import kotlinx.coroutines.flow.SharingStarted
1213
import kotlinx.coroutines.flow.combine
1314
import kotlinx.coroutines.flow.debounce
@@ -21,10 +22,7 @@ import org.session.libsignal.utilities.Log
2122
import org.thoughtcrime.securesms.database.ThreadDatabase
2223
import org.thoughtcrime.securesms.dependencies.ConfigFactory
2324
import org.thoughtcrime.securesms.search.SearchRepository
24-
import org.thoughtcrime.securesms.search.model.SearchResult
2525
import javax.inject.Inject
26-
import kotlin.coroutines.resume
27-
import kotlin.coroutines.suspendCoroutine
2826

2927
@OptIn(ExperimentalCoroutinesApi::class)
3028
@HiltViewModel
@@ -45,9 +43,9 @@ class GlobalSearchViewModel @Inject constructor(
4543
configFactory.configUpdateNotifications
4644
)
4745

48-
val noteToSelfString by lazy { application.getString(R.string.noteToSelf).lowercase() }
46+
val noteToSelfString: String by lazy { application.getString(R.string.noteToSelf).lowercase() }
4947

50-
val result = combine(
48+
val result: SharedFlow<GlobalSearchResult> = combine(
5149
_queryText,
5250
observeChangesAffectingSearch().onStart { emit(Unit) }
5351
) { query, _ -> query }
@@ -64,7 +62,7 @@ class GlobalSearchViewModel @Inject constructor(
6462
)
6563
}
6664
} else {
67-
val results = searchRepository.suspendQuery(query).toGlobalSearchResult()
65+
val results = searchRepository.query(query).toGlobalSearchResult()
6866

6967
// show "Note to Self" is the user searches for parts of"Note to Self"
7068
if(noteToSelfString.contains(query.lowercase())){
@@ -85,8 +83,3 @@ class GlobalSearchViewModel @Inject constructor(
8583
}
8684
}
8785

88-
private suspend fun SearchRepository.suspendQuery(query: String): SearchResult {
89-
return suspendCoroutine { cont ->
90-
query(query, cont::resume)
91-
}
92-
}

0 commit comments

Comments
 (0)