fix(navigation): fully reset ConversationListStateHolder on logout
reset() now clears pagination cursor, hasMore, isLoadingMore and isRefreshing state so the next user session does not inherit stuck spinners or stale cursors from the previous session. Also cancel and restart the search debounce collector so an in-flight debounced emission from the previous session cannot land after reset() and clobber the cleared grouped conversations list.
This commit is contained in:
parent
4814f8a5b5
commit
c613175c6e
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 kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
|
@ -49,6 +50,8 @@ class ConversationListStateHolder(
|
|||
private val _isRefreshing = MutableStateFlow(false)
|
||||
val isRefreshing: StateFlow<Boolean> = _isRefreshing.asStateFlow()
|
||||
|
||||
private var searchObserverJob: Job? = null
|
||||
|
||||
init {
|
||||
observeConversations()
|
||||
observeSearchQuery()
|
||||
|
|
@ -130,7 +133,8 @@ class ConversationListStateHolder(
|
|||
|
||||
@OptIn(FlowPreview::class)
|
||||
private fun observeSearchQuery() {
|
||||
scope.launch {
|
||||
searchObserverJob?.cancel()
|
||||
searchObserverJob = scope.launch {
|
||||
_searchQuery
|
||||
.filter { it.isNotBlank() }
|
||||
.debounce(SEARCH_DEBOUNCE_MS)
|
||||
|
|
@ -144,10 +148,17 @@ class ConversationListStateHolder(
|
|||
}
|
||||
|
||||
fun reset() {
|
||||
searchObserverJob?.cancel()
|
||||
searchObserverJob = null
|
||||
_recentConversations.value = emptyList()
|
||||
_groupedConversations.value = emptyList()
|
||||
_activeConversationId.value = null
|
||||
_searchQuery.value = ""
|
||||
nextCursor = null
|
||||
_hasMore.value = true
|
||||
_isLoadingMore.value = false
|
||||
_isRefreshing.value = false
|
||||
observeSearchQuery()
|
||||
}
|
||||
|
||||
private fun groupConversationsByDate(
|
||||
|
|
|
|||
Loading…
Reference in a new issue