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:
@@ -1,31 +1,41 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'chat_stack_actions.dart';
|
||||
import 'chat_stack_close_target.dart';
|
||||
import 'chat_stack_column_items.dart';
|
||||
import 'chat_stack_disc.dart';
|
||||
import 'chat_stack_drag.dart';
|
||||
import 'chat_stack_entry.dart';
|
||||
import 'chat_stack_group_dialogs.dart';
|
||||
import 'chat_stack_group_ops.dart';
|
||||
import 'chat_stack_group_pile.dart';
|
||||
import 'chat_stack_motion.dart';
|
||||
import 'chat_stack_close_target.dart';
|
||||
import 'chat_stack_node.dart';
|
||||
|
||||
part 'chat_stack_column_groups.dart';
|
||||
|
||||
/// The chat stack fanned out: a scrim over the screen and the open chats in
|
||||
/// a column rising from the stack's own slot, each avatar with its name in a
|
||||
/// small pill beside it, and Add chat at the top.
|
||||
///
|
||||
/// The stack's own slot turns into a close button ([ChatStackCloseTarget]);
|
||||
/// item 0 sits a pitch above it, nearest the thumb. The chats
|
||||
/// keep the open-chat order (the order the server syncs), so a chat keeps
|
||||
/// its place in the column from one visit to the next; the chat on screen
|
||||
/// wears a ring in its colour. Add chat is last, at the top: the reachable
|
||||
/// bottom slots go to the frequent action (switching), and the rarer one
|
||||
/// ends the list where the operator reads "and more".
|
||||
/// item 0 sits a pitch above it, nearest the thumb. The items keep the
|
||||
/// open-chat order (the order the server syncs), so a chat keeps its place
|
||||
/// from one visit to the next; the chat on screen wears a ring in its
|
||||
/// colour. A group shows as one item, its chats piled; a tap opens it: the
|
||||
/// top level fades and the group's chats rise from its pile, under a
|
||||
/// header that leads back. Add chat is last, at the top: the reachable
|
||||
/// bottom slots go to the frequent action (switching).
|
||||
///
|
||||
/// A short hold lifts a chat ([ChatStackDrag]): dragged up or down it
|
||||
/// reorders the open chats, the others sliding aside to open its slot;
|
||||
/// dropped on the close button (armed as a remove target while dragging)
|
||||
/// it leaves them. Add chat
|
||||
/// stays put. The same moves are semantic actions on each chat.
|
||||
/// A short hold lifts an item ([ChatStackDrag]): dragged up or down it
|
||||
/// reorders; dropped on the middle of another it groups them (or joins the
|
||||
/// group); dropped on the close button (armed as a remove target while
|
||||
/// dragging) a chat leaves the open chats and a group is ungrouped. In an
|
||||
/// open group a chat dropped on the header leaves the group. Add chat stays
|
||||
/// put. The same moves are semantic actions.
|
||||
///
|
||||
/// Nothing here rebuilds per frame: every item moves through
|
||||
/// `ChatStackPoseTransition` and `ChatStackDragShift` and fades through
|
||||
@@ -36,21 +46,25 @@ class ChatStackColumn extends StatefulWidget {
|
||||
super.key,
|
||||
required this.motion,
|
||||
required this.anchor,
|
||||
required this.entries,
|
||||
required this.nodes,
|
||||
required this.depths,
|
||||
required this.interactive,
|
||||
required this.onOpen,
|
||||
required this.onAdd,
|
||||
required this.onDismiss,
|
||||
required this.group,
|
||||
this.onRemove,
|
||||
this.onReorder,
|
||||
this.groups,
|
||||
});
|
||||
|
||||
final ChatStackMotion motion;
|
||||
|
||||
/// The collapsed stack's slot in this overlay's coordinates.
|
||||
final Rect anchor;
|
||||
final List<ChatStackEntry> entries;
|
||||
|
||||
/// The top level: chats and groups in the open-chat order.
|
||||
final List<ChatStackNode> nodes;
|
||||
|
||||
/// Each item's layer in the collapsed pile (null when it is not drawn
|
||||
/// there); the add item last.
|
||||
@@ -62,25 +76,34 @@ class ChatStackColumn extends StatefulWidget {
|
||||
final VoidCallback onAdd;
|
||||
final VoidCallback onDismiss;
|
||||
|
||||
/// Removes a chat from the open chats (dropped on the "×"); null when it
|
||||
/// cannot (the only open chat).
|
||||
/// The open group's name, or null on the top level; Back sets it null.
|
||||
final ValueNotifier<String?> group;
|
||||
|
||||
/// Removes a chat from the open chats; null when it cannot (the only open
|
||||
/// chat).
|
||||
final ValueChanged<ChatStackEntry>? onRemove;
|
||||
|
||||
/// Moves a chat to an index of the open-chat order; null when the chats
|
||||
/// cannot be reordered.
|
||||
final void Function(ChatStackEntry entry, int index)? onReorder;
|
||||
/// Puts the open chats in this order (session ids); null when they cannot
|
||||
/// be reordered.
|
||||
final ValueChanged<List<String>>? onReorder;
|
||||
|
||||
/// Grouping; null when the host keeps no groups.
|
||||
final ChatStackGroupActions? groups;
|
||||
|
||||
static const removeLabel = 'Remove from open chats';
|
||||
static const moveUpLabel = 'Move up';
|
||||
static const moveDownLabel = 'Move down';
|
||||
static const addLabel = 'Add chat';
|
||||
static const moveToGroupLabel = 'Move to group…';
|
||||
static const leaveGroupLabel = 'Remove from group';
|
||||
static const addLabel = ChatStackAddTail.label;
|
||||
|
||||
@override
|
||||
State<ChatStackColumn> createState() => _ChatStackColumnState();
|
||||
}
|
||||
|
||||
class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
with TickerProviderStateMixin {
|
||||
with TickerProviderStateMixin, _ChatStackColumnGroups {
|
||||
@override
|
||||
late final ChatStackDrag _drag = ChatStackDrag(
|
||||
vsync: this,
|
||||
pitch: kChatStackPitch,
|
||||
@@ -89,14 +112,11 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
/// The remove target's centre in this column's box, from the last layout.
|
||||
Offset? _removeCenter;
|
||||
|
||||
List<ChatStackEntry> get _entries => widget.entries;
|
||||
List<String> get _ids => [for (final entry in _entries) entry.paneId];
|
||||
|
||||
/// A hold lifts a chat when there is something to do with it.
|
||||
bool get _draggable =>
|
||||
widget.interactive &&
|
||||
((widget.onReorder != null && _entries.length > 1) ||
|
||||
widget.onRemove != null);
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initGroups();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
@@ -107,17 +127,19 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
@override
|
||||
void didUpdateWidget(covariant ChatStackColumn oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
// Folding, or the open chats changing under the finger (another
|
||||
// device), puts the dragged chat back.
|
||||
// Folding, or the items changing under the finger (another device),
|
||||
// puts the dragged item back.
|
||||
if (!widget.interactive ||
|
||||
(_drag.dragging && !listEquals(_ids, _drag.order))) {
|
||||
(_drag.dragging && !listEquals(_dragOrder(), _drag.order))) {
|
||||
_drag.cancel();
|
||||
}
|
||||
_groupsUpdated(oldWidget);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_drag.dispose();
|
||||
_disposeGroups();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -125,10 +147,7 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
if (mounted) setState(() {});
|
||||
}
|
||||
|
||||
void _start(ChatStackEntry entry) {
|
||||
if (_draggable) _drag.start(entry.paneId, _ids);
|
||||
}
|
||||
|
||||
@override
|
||||
void _move(LongPressMoveUpdateDetails details) {
|
||||
if (!_drag.dragging) return;
|
||||
final box = context.findRenderObject() as RenderBox?;
|
||||
@@ -142,19 +161,20 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
_drag.move(details.offsetFromOrigin, overRemove: over);
|
||||
}
|
||||
|
||||
void _end(ChatStackEntry entry) {
|
||||
if (!_drag.dragging) return;
|
||||
switch (_drag.end()) {
|
||||
case ChatStackDropMove(:final index):
|
||||
widget.onReorder?.call(entry, index);
|
||||
case ChatStackDropRemove():
|
||||
widget.onRemove?.call(entry);
|
||||
case ChatStackDropBack():
|
||||
break;
|
||||
void _escape() {
|
||||
if (_drag.dragging) {
|
||||
_drag.cancel();
|
||||
} else if (widget.group.value != null) {
|
||||
widget.group.value = null;
|
||||
} else {
|
||||
widget.onDismiss();
|
||||
}
|
||||
}
|
||||
|
||||
void _escape() => _drag.dragging ? _drag.cancel() : widget.onDismiss();
|
||||
/// A tap on the scrim: out of an open group first, then folded.
|
||||
void _scrim() => widget.group.value != null
|
||||
? widget.group.value = null
|
||||
: widget.onDismiss();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -163,29 +183,24 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
final dark = Theme.of(context).brightness == Brightness.dark;
|
||||
final rtl = Directionality.of(context) == TextDirection.rtl;
|
||||
final anchor = widget.anchor;
|
||||
final depths = widget.depths;
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final size = constraints.biggest;
|
||||
final count = widget.motion.count;
|
||||
final open = _openGroupMotion(rtl);
|
||||
final count = open == null || open.count < widget.motion.count
|
||||
? widget.motion.count
|
||||
: open.count;
|
||||
// The stack's own slot (the close button) and the items above it.
|
||||
final height = count * kChatStackPitch + kChatStackSlot;
|
||||
final top = media.padding.top + 8;
|
||||
final available = anchor.bottom - top;
|
||||
final fits = height <= available;
|
||||
final fits = height <= anchor.bottom - top;
|
||||
// The column's own edge is the stack's; the labels take the rest of
|
||||
// the row back to a margin at the other side.
|
||||
final endInset = rtl ? anchor.left : size.width - anchor.right;
|
||||
const margin = 16.0;
|
||||
final width = size.width - endInset - margin;
|
||||
final labelMax = width - kChatStackSlot - kChatStackLabelGap;
|
||||
// Paint the pile's order while it opens: hidden layers first, the
|
||||
// top of the pile last; a lifted chat above them all.
|
||||
final order = [for (var i = 0; i < count; i++) i]
|
||||
..sort((a, b) => (depths[b] ?? 99).compareTo(depths[a] ?? 99));
|
||||
final lifted = _entries.indexWhere((e) => e.paneId == _drag.lifted);
|
||||
if (lifted >= 0) order.add(order.removeAt(order.indexOf(lifted)));
|
||||
// The close button takes the pile's place; while a chat is dragged
|
||||
// The close button takes the pile's place; while an item is dragged
|
||||
// it is the remove target.
|
||||
_removeCenter = anchor.center;
|
||||
final close = Positioned.fromRect(
|
||||
@@ -202,20 +217,12 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
),
|
||||
),
|
||||
);
|
||||
final items = ChatStackColumnItems(
|
||||
motion: widget.motion,
|
||||
entries: _entries,
|
||||
order: order,
|
||||
labelMax: labelMax,
|
||||
drag: _drag,
|
||||
draggable: _draggable,
|
||||
onOpen: widget.onOpen,
|
||||
onAdd: widget.onAdd,
|
||||
onRemove: widget.onRemove,
|
||||
onReorder: widget.onReorder,
|
||||
onDragStart: _start,
|
||||
onDragMove: _move,
|
||||
onDragEnd: _end,
|
||||
final layers = Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
_topLayer(labelMax, inGroup: _openGroup != null),
|
||||
if (open != null) _groupLayer(open, labelMax),
|
||||
],
|
||||
);
|
||||
return CallbackShortcuts(
|
||||
bindings: {const SingleActivator(LogicalKeyboardKey.escape): _escape},
|
||||
@@ -231,12 +238,12 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
child: ModalBarrier(
|
||||
color: scheme.scrim.withValues(alpha: dark ? .5 : .32),
|
||||
dismissible: true,
|
||||
onDismiss: widget.onDismiss,
|
||||
onDismiss: _scrim,
|
||||
semanticsLabel: 'Dismiss',
|
||||
),
|
||||
),
|
||||
),
|
||||
// A dragged chat is drawn over the button (it shrinks into
|
||||
// A dragged item is drawn over the button (it shrinks into
|
||||
// it); otherwise the button is on top, to take its tap.
|
||||
if (_drag.lifted != null) close,
|
||||
PositionedDirectional(
|
||||
@@ -257,7 +264,7 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
container: true,
|
||||
explicitChildNodes: true,
|
||||
label: 'Open chats',
|
||||
child: items,
|
||||
child: layers,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -272,4 +279,43 @@ class _ChatStackColumnState extends State<ChatStackColumn>
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// The top level: chats, groups and Add chat. Behind an open group it
|
||||
/// fades out and takes no input.
|
||||
Widget _topLayer(double labelMax, {required bool inGroup}) {
|
||||
final nodes = widget.nodes;
|
||||
final depths = widget.depths;
|
||||
final order = [for (var i = 0; i <= nodes.length; i++) i]
|
||||
..sort((a, b) => (depths[b] ?? 99).compareTo(depths[a] ?? 99));
|
||||
_liftToTop(order, nodes);
|
||||
final items = ChatStackColumnItems(
|
||||
key: const ValueKey('chat-stack-top'),
|
||||
motion: widget.motion,
|
||||
nodes: nodes,
|
||||
tail: const ChatStackAddTail(),
|
||||
order: order,
|
||||
labelMax: labelMax,
|
||||
drag: _drag,
|
||||
draggable: _draggable && !inGroup,
|
||||
onOpen: _openNode,
|
||||
onTail: widget.onAdd,
|
||||
onDragStart: _startTop,
|
||||
onDragMove: _move,
|
||||
onDragEnd: _endTop,
|
||||
actionsFor: _topActions,
|
||||
);
|
||||
return IgnorePointer(
|
||||
ignoring: inGroup,
|
||||
child: ExcludeSemantics(
|
||||
excluding: inGroup,
|
||||
child: FadeTransition(opacity: _topOpacity, child: items),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Paints a lifted item above the others.
|
||||
void _liftToTop(List<int> order, List<ChatStackNode> nodes) {
|
||||
final lifted = nodes.indexWhere((node) => node.key == _drag.lifted);
|
||||
if (lifted >= 0) order.add(order.removeAt(order.indexOf(lifted)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user