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:
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'chat_stack_groups.dart';
|
||||
|
||||
/// The group actions a group offers in its menu and as semantic actions.
|
||||
enum ChatStackGroupAction {
|
||||
rename('Rename group'),
|
||||
ungroup('Ungroup'),
|
||||
closeAll('Close all chats in group');
|
||||
|
||||
const ChatStackGroupAction(this.label);
|
||||
final String label;
|
||||
}
|
||||
|
||||
/// Asks for a group name, starting from [current] (selected, so typing
|
||||
/// replaces it); null when cancelled or left empty.
|
||||
Future<String?> showChatStackRenameDialog(
|
||||
BuildContext context, {
|
||||
required String current,
|
||||
String title = 'Rename group',
|
||||
}) => showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => _RenameDialog(current: current, title: title),
|
||||
);
|
||||
|
||||
class _RenameDialog extends StatefulWidget {
|
||||
const _RenameDialog({required this.current, required this.title});
|
||||
final String current;
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<_RenameDialog> createState() => _RenameDialogState();
|
||||
}
|
||||
|
||||
class _RenameDialogState extends State<_RenameDialog> {
|
||||
late final TextEditingController _name =
|
||||
TextEditingController(text: widget.current)
|
||||
..selection = TextSelection(
|
||||
baseOffset: 0,
|
||||
extentOffset: widget.current.length,
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_name.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _save() => Navigator.of(context).pop(chatStackGroupName(_name.text));
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AlertDialog(
|
||||
title: Text(widget.title),
|
||||
content: TextField(
|
||||
key: const Key('chat-stack-group-name'),
|
||||
controller: _name,
|
||||
autofocus: true,
|
||||
maxLength: chatStackGroupNameLimit,
|
||||
decoration: const InputDecoration(labelText: 'Group name'),
|
||||
textInputAction: TextInputAction.done,
|
||||
onSubmitted: (_) => _save(),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(onPressed: _save, child: const Text('Save')),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Asks which of [groups] a chat moves to; null when cancelled.
|
||||
Future<String?> showChatStackMoveToGroupDialog(
|
||||
BuildContext context, {
|
||||
required List<String> groups,
|
||||
}) => showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => SimpleDialog(
|
||||
title: const Text('Move to group'),
|
||||
children: [
|
||||
for (final group in groups)
|
||||
SimpleDialogOption(
|
||||
onPressed: () => Navigator.of(context).pop(group),
|
||||
child: Text(group),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
/// The group's menu (Rename, Ungroup, Close all) at [anchor] (global).
|
||||
Future<ChatStackGroupAction?> showChatStackGroupMenu(
|
||||
BuildContext context, {
|
||||
required Rect anchor,
|
||||
}) {
|
||||
final overlay = Overlay.of(context).context.findRenderObject() as RenderBox;
|
||||
final local = Rect.fromPoints(
|
||||
overlay.globalToLocal(anchor.topLeft),
|
||||
overlay.globalToLocal(anchor.bottomRight),
|
||||
);
|
||||
return showMenu<ChatStackGroupAction>(
|
||||
context: context,
|
||||
position: RelativeRect.fromRect(local, Offset.zero & overlay.size),
|
||||
items: [
|
||||
for (final action in ChatStackGroupAction.values)
|
||||
PopupMenuItem(value: action, child: Text(action.label)),
|
||||
],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user