Chat stack: groups of open chats, synced with the open-chat set

A chat dropped onto the middle of another makes a named group (asked at
once, "Group N" by default); onto a group it joins, a group dropped onto
a chat takes it in, groups merge. The top level shows each group as a
small pile with its name and count; a tap opens it in place under a
header that leads back (also the scrim, Back and Escape). In a group,
dropping a chat on the header leaves the group; a group of one
dissolves. The close button ungroups a dropped group with Undo. Rename,
Ungroup, Close all (with Undo), Move to group and Remove from group are
in the group menu and as semantic actions.

Each open-chat entry carries its group name (protocol field "group",
omitted when ungrouped; older clients ignore it), stored and pushed by
the server like the order; names are trimmed, printable, at most 80
characters. Needs a server restart to keep groups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 22:18:44 +00:00
parent 130c1e6708
commit efaa0d9fca
30 changed files with 2399 additions and 308 deletions
@@ -3,10 +3,12 @@ import 'package:flutter/material.dart';
import '../../../ui/motion/motion.dart';
import '../../../ui/theme/app_design_tokens.dart';
import '../ui/sessions/chat_awaiting.dart';
import 'chat_stack_actions.dart';
import 'chat_stack_column.dart';
import 'chat_stack_disc.dart';
import 'chat_stack_entry.dart';
import 'chat_stack_motion.dart';
import 'chat_stack_node.dart';
import 'chat_stack_pose.dart';
/// The phone's chat stack: the open chats' avatars piled up, the chat on
@@ -21,6 +23,7 @@ class ChatStackFab extends StatefulWidget {
required this.onAdd,
this.onRemove,
this.onReorder,
this.groups,
});
/// The open chats in their synced order; one is [ChatStackEntry.current].
@@ -31,9 +34,12 @@ class ChatStackFab extends StatefulWidget {
final ValueChanged<BuildContext> onAdd;
final ValueChanged<ChatStackEntry>? onRemove;
/// Moves a chat to an index of the open-chat order (a drag in the open
/// column, or its Move up and Move down actions).
final void Function(ChatStackEntry entry, int index)? onReorder;
/// Puts the open chats in this order (session ids): a drag in the open
/// column, or its Move up and Move down actions.
final ValueChanged<List<String>>? onReorder;
/// Grouping the open chats; null when the host keeps no groups.
final ChatStackGroupActions? groups;
@override
State<ChatStackFab> createState() => ChatStackFabState();
@@ -53,6 +59,9 @@ class ChatStackFabState extends State<ChatStackFab>
final _slot = GlobalKey(debugLabel: 'Chat stack slot');
final _focus = FocusNode(debugLabel: 'Chat stack');
/// The group open in the column, or null on its top level.
final _group = ValueNotifier<String?>(null);
/// The pile hides the moment the column starts to move; under reduced
/// motion the two cross-fade in place instead.
late final Animation<double> _hiddenWhileOpen = _open.drive(_ShownAtRest());
@@ -99,6 +108,7 @@ class ChatStackFabState extends State<ChatStackFab>
_motion?.dispose();
_open.dispose();
_focus.dispose();
_group.dispose();
super.dispose();
}
@@ -133,6 +143,7 @@ class ChatStackFabState extends State<ChatStackFab>
/// Folds the column back into the stack; [immediate] skips the motion.
void collapse({bool immediate = false}) {
if (!_expanded) return;
_group.value = null;
setState(() => _expanded = false);
if (immediate) {
_open.value = 0;
@@ -161,6 +172,39 @@ class ChatStackFabState extends State<ChatStackFab>
widget.onAdd(context);
}
/// The groups' actions; ungrouping and closing fold the column, so the
/// snack bar's Undo is in reach.
ChatStackGroupActions? _groupActions() {
final groups = widget.groups;
if (groups == null) return null;
return ChatStackGroupActions(
join: groups.join,
leave: groups.leave,
rename: groups.rename,
ungroup: (group) {
collapse();
groups.ungroup(group);
},
closeAll: (group) {
collapse();
groups.closeAll(group);
},
);
}
/// Each top-level item's layer in the pile: a group's is its top chat's.
List<int?> _nodeDepths(List<ChatStackNode> nodes, List<int?> depths) {
final entries = widget.entries;
return [
for (final node in nodes)
node.entries
.map((entry) => depths[entries.indexOf(entry)])
.whereType<int>()
.fold<int?>(null, (a, b) => a == null || b < a ? b : a),
null,
];
}
/// Each item's layer in the pile: the chat on screen on top, then the
/// chats after it in order, wrapping; the add item is never in the pile.
List<int?> _depths() {
@@ -196,15 +240,23 @@ class ChatStackFabState extends State<ChatStackFab>
Widget build(BuildContext context) {
final entries = widget.entries;
final depths = _depths();
final nodes = chatStackNodes(entries);
final nodeDepths = _nodeDepths(nodes, depths);
final rtl = Directionality.of(context) == TextDirection.rtl;
final motion = _motionFor(depths, rtl);
final motion = _motionFor(nodeDepths, rtl);
final hidden = _keyboard || entries.isEmpty;
final remove = widget.onRemove;
final canRemove = remove != null && entries.length > 1;
return PopScope(
canPop: !_expanded,
onPopInvokedWithResult: (didPop, _) {
if (!didPop) collapse();
if (didPop) return;
// Back leaves an open group first.
if (_group.value != null) {
_group.value = null;
} else {
collapse();
}
},
child: OverlayPortal(
controller: _portal,
@@ -214,14 +266,16 @@ class ChatStackFabState extends State<ChatStackFab>
return ChatStackColumn(
motion: motion,
anchor: anchor,
entries: entries,
depths: depths,
nodes: nodes,
depths: nodeDepths,
group: _group,
interactive: _expanded,
onOpen: _choose,
onAdd: _add,
onDismiss: collapse,
onRemove: canRemove ? _remove : null,
onReorder: widget.onReorder,
groups: _groupActions(),
);
},
child: AnimatedOpacity(