Open selected chats from search

Re-apply explicit chat routes after workspace restoration and repeated route notifications so search results and chat notifications open the requested session. Add regression coverage for route, registration, and workspace restore behavior.
This commit is contained in:
2026-11-13 15:58:16 +00:00
parent eeb07e5645
commit ec3c1e4c6a
8 changed files with 241 additions and 12 deletions
+29 -11
View File
@@ -357,6 +357,7 @@ class _ChatScreenState extends State<ChatScreen>
/// Opens the chat the route names. A chat opened for work from elsewhere
/// (Open in chat) goes beside the active chat on a wide layout instead of
/// replacing it, and takes the keyboard once its composer is built.
@override
void _openRouted(String id) {
if (!_runtime.openedForWork.remove(id)) {
_workspace.open(id);
@@ -400,17 +401,34 @@ class _ChatScreenState extends State<ChatScreen>
void didUpdateWidget(covariant ChatScreen oldWidget) {
super.didUpdateWidget(oldWidget);
final reboundWorkspace = _updateWorkspacePersistence(oldWidget);
if (!reboundWorkspace &&
oldWidget.initialSessionId != widget.initialSessionId) {
_workspaceBinding?.changed();
final id = widget.initialSessionId;
if (id != null && id.isNotEmpty) {
_workspaceVisible = true;
_publishedWorkspaceSession = id;
_openRouted(id);
} else if (widget.onSessionSelected != null) {
_workspaceVisible = false;
}
final id = widget.initialSessionId;
final routeChanged = oldWidget.initialSessionId != id;
final targetIsNotActive =
id != null &&
id.isNotEmpty &&
(_workspace.activePane?.sessionId != id || !_workspaceVisible);
if (!reboundWorkspace && (routeChanged || targetIsNotActive)) {
// The parent is rebuilding while didUpdateWidget runs. Opening a pane
// notifies the workspace's ListenableBuilder, which must happen after
// this build rather than during it.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
final currentId = widget.initialSessionId;
_workspaceBinding?.changed();
if (currentId != null && currentId.isNotEmpty) {
if (_workspace.activePane?.sessionId == currentId &&
_workspaceVisible) {
return;
}
setState(() {
_workspaceVisible = true;
_publishedWorkspaceSession = currentId;
});
_openRouted(currentId);
} else if (routeChanged && widget.onSessionSelected != null) {
setState(() => _workspaceVisible = false);
}
});
}
// Transcripts read through another gateway belong to that server.
_runtime.gateway = widget.gateway;