efaa0d9fca
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>
77 lines
2.2 KiB
Dart
77 lines
2.2 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
import 'chat_stack_entry.dart';
|
|
|
|
/// One item of the open column's top level: a chat, or a group of chats.
|
|
@immutable
|
|
sealed class ChatStackNode {
|
|
const ChatStackNode();
|
|
|
|
/// Stable across rebuilds and reorders: keys widgets and drag state.
|
|
String get key;
|
|
|
|
/// The chats it stands for, in order.
|
|
List<ChatStackEntry> get entries;
|
|
|
|
/// Whether the chat on screen is in it.
|
|
bool get current => entries.any((entry) => entry.current);
|
|
|
|
/// Unanswered approvals and questions across its chats.
|
|
int get awaitingOperator =>
|
|
entries.fold(0, (sum, entry) => sum + entry.awaitingOperator);
|
|
}
|
|
|
|
/// A chat on its own.
|
|
class ChatStackChatNode extends ChatStackNode {
|
|
const ChatStackChatNode(this.entry);
|
|
final ChatStackEntry entry;
|
|
|
|
@override
|
|
String get key => 'chat:${entry.paneId}';
|
|
|
|
@override
|
|
List<ChatStackEntry> get entries => [entry];
|
|
}
|
|
|
|
/// A named group of chats.
|
|
class ChatStackGroupNode extends ChatStackNode {
|
|
const ChatStackGroupNode(this.name, this.entries);
|
|
final String name;
|
|
|
|
@override
|
|
final List<ChatStackEntry> entries;
|
|
|
|
@override
|
|
String get key => 'group:$name';
|
|
}
|
|
|
|
/// [entries] (in the open-chat order) as the top level shows them: each
|
|
/// group where its first chat is, holding its chats in order, and the
|
|
/// ungrouped chats on their own.
|
|
List<ChatStackNode> chatStackNodes(List<ChatStackEntry> entries) {
|
|
final groups = <String, List<ChatStackEntry>>{};
|
|
for (final entry in entries) {
|
|
final group = entry.group;
|
|
if (group != null) (groups[group] ??= []).add(entry);
|
|
}
|
|
final nodes = <ChatStackNode>[];
|
|
final placed = <String>{};
|
|
for (final entry in entries) {
|
|
final group = entry.group;
|
|
final members = group == null ? null : groups[group];
|
|
if (group == null || members == null || members.length < 2) {
|
|
nodes.add(ChatStackChatNode(entry));
|
|
} else if (placed.add(group)) {
|
|
nodes.add(ChatStackGroupNode(group, List.unmodifiable(members)));
|
|
}
|
|
}
|
|
return nodes;
|
|
}
|
|
|
|
/// The open-chat order (session ids) [nodes] stand for, each group's chats
|
|
/// together.
|
|
List<String> chatStackOrder(Iterable<ChatStackNode> nodes) => [
|
|
for (final node in nodes)
|
|
for (final entry in node.entries) entry.sessionId,
|
|
];
|