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:
@@ -10,6 +10,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
bool _chatOwnsKeyboard();
|
||||
JsonMap? _rowFor(String id);
|
||||
void _back();
|
||||
void _openRouted(String id);
|
||||
bool get _pageOpen;
|
||||
Widget _thread(ChatWorkspacePane pane);
|
||||
|
||||
@@ -185,6 +186,17 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
_usedWorkspace = true;
|
||||
_workspaceVisible = _workspace.paneCount > 0;
|
||||
});
|
||||
// A route can arrive while the local workspace is being restored.
|
||||
// Re-apply it after restore so the saved active pane cannot overwrite
|
||||
// an explicit notification or Search selection.
|
||||
final id = widget.initialSessionId;
|
||||
if (id != null &&
|
||||
id.isNotEmpty &&
|
||||
_workspace.activePane?.sessionId != id) {
|
||||
_workspaceVisible = true;
|
||||
_publishedWorkspaceSession = id;
|
||||
_openRouted(id);
|
||||
}
|
||||
_publishWorkspaceRoute();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user