Reset ViewModels on logout/account switch

This commit introduces a `ResetModel()` function to `AgentViewModel` and `MineAgentViewModel` to clear their state.

This function is now called in `ResourceCleanupManager` and `AppState` during logout or when switching accounts to ensure that data from the previous session is not retained.

Additionally, the search and group name input fields in `CreateGroupChatScreen` are now single-line.
This commit is contained in:
2025-09-01 15:36:22 +08:00
parent 5c12982908
commit 36d322ef8c
5 changed files with 39 additions and 16 deletions

View File

@@ -63,7 +63,7 @@ object ResourceCleanupManager {
IndexViewModel.ResetModel()
// 重置AI相关ViewModel
// AgentViewModel的属性是私有的,无法直接访问,通过其他方式清理
AgentViewModel.ResetModel()
HotAgentViewModel.let {
it.agentList = emptyList()
@@ -75,13 +75,7 @@ object ResourceCleanupManager {
it.clearPreloadedImages()
}
MineAgentViewModel.let {
it.refreshing = false
it.isLoading = false
it.hasNext = true
it.currentPage = 1
it.error = null
}
MineAgentViewModel.ResetModel()
// 重置动态相关ViewModel
TimelineMomentViewModel.ResetModel()
@@ -220,7 +214,7 @@ object ResourceCleanupManager {
fun cleanupPageResources(pageType: String) {
when (pageType) {
"ai" -> {
// AgentViewModel的属性是私有的,无法直接访问
AgentViewModel.ResetModel()
HotAgentViewModel.let {
it.agentList = emptyList()
it.refreshing = false
@@ -230,13 +224,7 @@ object ResourceCleanupManager {
it.error = null
it.clearPreloadedImages()
}
MineAgentViewModel.let {
it.refreshing = false
it.isLoading = false
it.hasNext = true
it.currentPage = 1
it.error = null
}
MineAgentViewModel.ResetModel()
}
"moment" -> {
TimelineMomentViewModel.ResetModel()