Merge pull request #42 from garfiec/fix/conversation-list-state-reset
fix(navigation): fully reset ConversationListStateHolder on logout
This commit is contained in:
commit
8463b1fc9f
1 changed files with 12 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ import com.garfiec.librechat.core.data.repository.ConversationRepository
|
||||||
import com.garfiec.librechat.core.model.Conversation
|
import com.garfiec.librechat.core.model.Conversation
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.FlowPreview
|
import kotlinx.coroutines.FlowPreview
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
@ -49,6 +50,8 @@ class ConversationListStateHolder(
|
||||||
private val _isRefreshing = MutableStateFlow(false)
|
private val _isRefreshing = MutableStateFlow(false)
|
||||||
val isRefreshing: StateFlow<Boolean> = _isRefreshing.asStateFlow()
|
val isRefreshing: StateFlow<Boolean> = _isRefreshing.asStateFlow()
|
||||||
|
|
||||||
|
private var searchObserverJob: Job? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
observeConversations()
|
observeConversations()
|
||||||
observeSearchQuery()
|
observeSearchQuery()
|
||||||
|
|
@ -130,7 +133,8 @@ class ConversationListStateHolder(
|
||||||
|
|
||||||
@OptIn(FlowPreview::class)
|
@OptIn(FlowPreview::class)
|
||||||
private fun observeSearchQuery() {
|
private fun observeSearchQuery() {
|
||||||
scope.launch {
|
searchObserverJob?.cancel()
|
||||||
|
searchObserverJob = scope.launch {
|
||||||
_searchQuery
|
_searchQuery
|
||||||
.filter { it.isNotBlank() }
|
.filter { it.isNotBlank() }
|
||||||
.debounce(SEARCH_DEBOUNCE_MS)
|
.debounce(SEARCH_DEBOUNCE_MS)
|
||||||
|
|
@ -144,10 +148,17 @@ class ConversationListStateHolder(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reset() {
|
fun reset() {
|
||||||
|
searchObserverJob?.cancel()
|
||||||
|
searchObserverJob = null
|
||||||
_recentConversations.value = emptyList()
|
_recentConversations.value = emptyList()
|
||||||
_groupedConversations.value = emptyList()
|
_groupedConversations.value = emptyList()
|
||||||
_activeConversationId.value = null
|
_activeConversationId.value = null
|
||||||
_searchQuery.value = ""
|
_searchQuery.value = ""
|
||||||
|
nextCursor = null
|
||||||
|
_hasMore.value = true
|
||||||
|
_isLoadingMore.value = false
|
||||||
|
_isRefreshing.value = false
|
||||||
|
observeSearchQuery()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun groupConversationsByDate(
|
private fun groupConversationsByDate(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue