Files
pipelines/app/lib/features/chat/chat_screen_float.dart
T
alan 4f8e99f316 Serialize open-chat sync writes by server revision and fan out prunes
Server: chat_open_workspace is a compare-and-swap on base_revision; a stale
write is refused and answered with the current snapshot (rejected: true).
Each stored change increments the revision; identical writes store nothing.
A request with no body reads the set. Seeds apply only to a never-stored set.
Validation uses the operator registry (recorded, not closed). chat_close and
connection-time pruning store a new revision and push it to every
connection; otherwise a new connection gets the current set to catch up.

App: ChatOpenWorkspaceController keeps one write in flight, coalesces later
changes, sends from the last replied revision and ignores lower revisions;
pushes and rejected replies win over unsent changes. It starts after the
local layout restores (seed or read), keeps a deep-linked chat, and is
disposed on server/gateway rebind. Remote membership is applied by
reconcileChatWorkspaceTree, keeping pane ids and split sizes. Federated
lists keep their local layout.

Tests: Go store/handler fan-out tests; app controller, reconcile and screen
sync tests. Notes record a live two-client scratch check.
2026-11-12 03:23:22 +00:00

90 lines
2.8 KiB
Dart

part of 'screen.dart';
/// Floating a tiled pane into a window and docking it back (see
/// [ChatWindows] and `notes/chat-floating-pane.md`).
mixin _ChatScreenFloat on State<ChatScreen>, _ChatScreenWorkspace {
ChatTiling? _tiling;
void _bindWindows() {
final windows = widget.windows;
if (windows == null) return;
_workspace.showOutside = windows.show;
windows.tiling = _tiling = ChatTiling(
holds: _workspace.holdsSession,
dock: _dockSession,
canFloatActive: () {
final pane = _workspace.activePane;
return mounted &&
pane != null &&
_floatsHere &&
_workspaceVisible &&
_workspace.canFloat(pane.id) &&
_chatOwnsKeyboard();
},
floatActive: () {
final pane = _workspace.activePane;
if (pane != null) _floatPane(pane.id);
},
);
}
void _unbindWindows() {
final windows = widget.windows;
if (windows != null && identical(windows.tiling, _tiling)) {
windows.tiling = null;
}
_workspace.showOutside = null;
}
/// Panes float only on a wide layout, beside the chat list.
bool get _floatsHere =>
widget.windows != null && !_pageOpen && showsListBesideDetail(context);
/// The pane leaves the tiling and its live view moves into a window in
/// the same frame.
void _floatPane(String paneId) {
final pane = _workspace.detach(paneId);
if (pane == null) return;
widget.windows?.float(pane.sessionId);
_syncOpenWorkspace();
// Floating the last tiled chat leaves the list, as closing it does.
if (_workspace.paneCount == 0) _back();
}
/// The chat list's Float choice: a tiled chat leaves the tiling, a chat
/// already in a window comes to the top, any other opens in a new window.
void _floatSession(JsonMap session) {
final id = '${session['id'] ?? ''}';
final windows = widget.windows;
if (id.isEmpty || windows == null || windows.show(id)) return;
final pane = _workspace.panes.where((p) => p.sessionId == id).firstOrNull;
if (pane != null) {
_floatPane(pane.id);
} else {
windows.float(id);
_syncOpenWorkspace();
}
}
void _dockSession(String sessionId) {
if (!mounted) return;
_workspaceVisible = true;
if (!_pageOpen && showsListBesideDetail(context)) _usedWorkspace = true;
_workspace.dock(sessionId);
_syncOpenWorkspace();
_composerFocus.request(sessionId);
}
/// The pane menu's Float choice, on a tiled pane that can.
List<Widget> _floatControls(ChatWorkspacePane pane) {
if (!_floatsHere || !_workspace.canFloat(pane.id)) return const [];
return [
ChatBarAction(
label: 'Float (${chatFloatShortcutLabel()})',
onPressed: () => _floatPane(pane.id),
materialIcon: Icons.picture_in_picture_alt_outlined,
),
];
}
}