fix(notification): resume stored session before reply (#805)

This commit is contained in:
AlexDev_ authored and GitHub committed 2026-08-04 19:54:49 +03:00
1 parent e1a04a9396
commit 356ccc98b5
13 files changed
+268 -39

No files matched your search

@@ -845,7 +845,7 @@ class ChatViewModel(
// Mirror the active session id app-wide so session-scoped
// drawer screens (e.g. Processes, issue #532) can issue
// session-scoped RPCs. See ActiveSessionHolder.
ActiveSessionHolder.set(runtimeId)
ActiveSessionHolder.set(runtimeId, storageId)
_streamingState.update { StreamingState() }
addSystemMessage("Session created", persist = true)
loadSessions()
@@ -868,7 +868,7 @@ class ChatViewModel(
isLoading = false,
)
runtimeSessionId = runtimeId
ActiveSessionHolder.set(runtimeId)
ActiveSessionHolder.set(runtimeId, storageId)
sessionHasServerPresence = false
sessionGoneRecoveryInFlight = false
addSystemMessage("Session branched", persist = true)
@@ -938,7 +938,7 @@ class ChatViewModel(
)
}
// Mirror the active runtime session id app-wide (issue #532).
ActiveSessionHolder.set(runtimeSessionId ?: sessionId)
ActiveSessionHolder.set(runtimeSessionId ?: sessionId, sessionId)
addSystemMessage("Session resumed")
fetchContextUsage()
val generation = request?.generation ?: sessionGeneration
@@ -1848,7 +1848,7 @@ class ChatViewModel(
resumedGeneration = -1L
hydratedGeneration = -1L
runtimeSessionId = null
ActiveSessionHolder.set(sessionId)
ActiveSessionHolder.clear()
loadedMessageOffset = 0
isSyncingMessages = false
streamingController.resetStreaming()
@@ -10,7 +10,6 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat
import androidx.lifecycle.Lifecycle
@@ -48,20 +47,13 @@ fun ChatLifecycleEffects(
val context = LocalContext.current
val lifecycleOwner = LocalLifecycleOwner.current
// Publish the notification session ID to the ViewModel synchronously
SideEffect {
viewModel.initialSessionId = sessionId
}
// Switch to session from notification/history
LaunchedEffect(sessionId, NavigationController.pendingSessionId, connectionStatus) {
val pendingSessionId = NavigationController.pendingSessionId
LaunchedEffect(sessionId, pendingSessionId, connectionStatus) {
if (connectionStatus != ConnectionStatus.CONNECTED) return@LaunchedEffect
val target = if (!sessionId.isNullOrBlank()) sessionId else NavigationController.pendingSessionId
val target = NavigationController.consumePendingSessionId() ?: sessionId
if (!target.isNullOrBlank()) {
viewModel.switchSession(target)
if (target == NavigationController.pendingSessionId) {
NavigationController.pendingSessionId = null
}
}
}
@@ -555,8 +555,7 @@ fun SessionsScreen(
if (state.isSelecting) {
viewModel.toggleSessionSelection(session.id)
} else {
NavigationController.pendingSessionId = session.id
NavigationController.navigateTo(ChatScreen)
NavigationController.openChatSession(session.id)
}
},
onCardLongClick = {
@@ -691,8 +690,7 @@ fun SessionsScreen(
if (state.isSelecting) {
viewModel.toggleSessionSelection(session.id)
} else {
NavigationController.pendingSessionId = session.id
NavigationController.navigateTo(ChatScreen)
NavigationController.openChatSession(session.id)
}
},
onCardLongClick = {