Files
pipelines/app/lib/features/chat/chat_pane_content.dart
T
alan 746e23788d Mark chats seen after user interaction
Prevent passive open, restored, or unfocused chats from clearing notifications. Track qualifying focused interactions and cover passive and active seen-watermark behavior with tests and notes.
2026-11-12 02:25:09 +00:00

125 lines
4.6 KiB
Dart

import 'package:flutter/widgets.dart';
import '../../core/api_gateway.dart';
import '../../core/servers/server_context.dart';
import '../../shell/destination.dart';
import '../../shell/detail_page.dart';
import 'chat_runtime.dart';
import 'conversation/chat_seen_interaction.dart';
import 'conversation/chat_thread_view.dart';
import 'conversation/composer_focus_request.dart';
import 'workspace/chat_pane_commands.dart';
/// Where an open chat is shown and what that place alone decides: its Back,
/// its pane menu, whether it takes pastes, and what follows `/new` and
/// `/close`. Everything else about the chat comes from its [ChatRuntime].
class ChatPanePlacement {
const ChatPanePlacement({
required this.onBack,
required this.onNewSession,
required this.onSessionClosed,
this.syncToken = 0,
this.useNativeBack = false,
this.showBackButton,
this.pasteTarget = false,
this.ownsPasteWhenFocused = false,
this.paneControls,
this.paneCommands,
this.onNextChat,
});
final VoidCallback onBack;
/// `/new` moved the chat to a fresh session (previous id, the new row and
/// the line the new conversation opens on).
final void Function(String previousId, JsonMap session, String notice)
onNewSession;
/// `/close` was accepted.
final VoidCallback onSessionClosed;
/// Advances when the socket is replaced; the conversation re-subscribes.
final int syncToken;
final bool useNativeBack;
final bool? showBackButton;
/// Whether a paste with no field focused goes to this chat.
final bool pasteTarget;
/// Whether this chat takes a paste while it has the keyboard, though it is
/// not the active pane (a chat in a window).
final bool ownsPasteWhenFocused;
/// The pane menu's choices, built in the pane's own context.
final List<Widget> Function(BuildContext paneContext)? paneControls;
/// Choices the chat list hands to this chat's conversation to run.
final ChatPaneCommands? paneCommands;
final VoidCallback? onNextChat;
}
/// One open chat with the scopes its conversation needs, the same in the
/// Chat destination's tiling and in a floating window. It is keyed by the
/// runtime ([ChatRuntime.viewKey]), so a chat that moves between the two in
/// one frame keeps its live view: transcript, scroll, draft and running turn.
Widget buildChatPaneContent({
required ChatRuntime runtime,
required String sessionId,
required ChatPanePlacement placement,
}) => KeyedSubtree(
key: runtime.viewKey(sessionId),
child: DetailPane(
destination: AppDestination.chat,
implyBack: false,
builder: (context) {
final row = runtime.rowFor(sessionId);
final start = runtime.startNotice;
return ChatComposerFocusScope(
sessionId: sessionId,
requests: runtime.composerFocus,
child: ServerContext.forServer(
context,
runtime.serverIdFor(sessionId),
ChatSeenInteraction(
sessionId: sessionId,
onInteract: () => runtime.sessions.reportInteraction(sessionId),
child: ChatThreadView(
key: ValueKey<String>('chat-session-$sessionId'),
gateway: runtime.gatewayFor(sessionId),
sessionId: sessionId,
title: '${row?['title'] ?? ''}'.trim(),
session: row,
syncToken: placement.syncToken,
scrollPositions: runtime.scrollPositions,
transcripts: runtime.transcripts,
initialNotice: start != null && start.id == sessionId
? start.notice
: null,
onBack: placement.onBack,
onModelChanged: (applied) =>
runtime.modelChanged(sessionId, applied),
onModeChanged: (mode, name) =>
runtime.acceptMode(sessionId, mode, name),
onEffortChanged: (state) =>
runtime.acceptEffort(sessionId, state),
onNewSession: placement.onNewSession,
onSessionRenamed: (title) =>
runtime.acceptRename(sessionId, title),
onSessionClosed: placement.onSessionClosed,
onColorSelected: (color) =>
runtime.sessions.setColor(sessionId, color),
onNextChat: placement.onNextChat,
useNativeBack: placement.useNativeBack,
pasteTarget: placement.pasteTarget,
ownsPasteWhenFocused: placement.ownsPasteWhenFocused,
showBackButton: placement.showBackButton,
paneControls: placement.paneControls?.call(context) ?? const [],
paneCommands: placement.paneCommands,
),
),
),
);
},
),
);