Files
pipelines/app/lib/features/chat/ui/sessions/session_row_content.dart
T
alan f7b5958d64 App: chat colours, Ctrl+1-9 opens the Nth list item, starred chats alphabetical
A chat's colour is picked from its row menu (Colour...), a long-press or
the chat information sheet. The list shows it as a leading bar, a faint
row tint and a coloured avatar; the open chat shows a faint wash under its
top bar. Shades are Cupertino's dynamic system colours and Material
swatches tuned per brightness. Changes from other devices apply live.

Ctrl+1...Ctrl+9 open the Nth item of the open tab's list (chats, runs,
pipelines) in on-screen order, also while typing. Starred chats are sorted
by name, case-insensitively, as one alphabetical group.
2026-11-03 11:05:38 +00:00

232 lines
7.5 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../../../ui/layout/app_list_avatar.dart';
import '../../../../ui/layout/app_list_row.dart';
import '../../../../ui/text/relative_time_label.dart';
import '../../domain/chat_colors.dart';
import '../../domain/chat_sessions.dart';
import 'chat_adaptive.dart';
import 'chat_color_palette.dart';
import 'session_actions.dart';
import 'session_harness_icon.dart';
import 'session_row_style.dart';
/// One chat in the list, in the app's shared row on both hosts: the harness
/// avatar, the title with its recency, one muted line, and the actions menu.
///
/// An unread chat is emphasised (heavier title, accent time) with an accent
/// dot ending its line; a starred chat shows a small star after its title; a
/// running chat carries an activity badge on its avatar. A chat with a colour
/// wears it as a bar on the row's leading edge, a faint row tint and a
/// coloured avatar. A narrow pane drops the avatar and time but keeps the
/// colour bar and the menu, the list's only way to its actions.
class ChatSessionRow extends StatelessWidget {
const ChatSessionRow({
super.key,
required this.session,
required this.onOpen,
required this.onAction,
this.selected = false,
this.unseen = false,
this.divider = true,
this.duplicateTitles = const {},
this.onLongPress,
});
final JsonMap session;
final ValueChanged<JsonMap> onOpen;
final VoidCallback? onLongPress;
final ValueChanged<SessionAction> onAction;
final bool selected;
final bool unseen;
final bool divider;
final Set<String> duplicateTitles;
@override
Widget build(BuildContext context) {
final id = '${session['id'] ?? ''}';
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final closed = chatSessionRowStatus(session, unseen: false) == 'Closed';
final unread = unseen && !closed;
final accent = cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary;
final text = chatSessionSubtitle(session);
final updatedAt = _chatSessionInstant(session['updated_at']);
return AppListRow(
key: Key('chat-row-$id'),
cupertino: cupertino,
selected: selected,
emphasized: unread,
divider: divider,
keepMenuWhenCompact: true,
onTap: () => onOpen(session),
onLongPress: onLongPress,
accent: chatColorShade(context, chatSessionColor(session)),
leading: ChatSessionAvatar(
session: session,
running: session['running'] == true && !unseen,
selected: selected,
),
// The star rides in the title's own text, so a narrow row ellipsises
// them together.
title: Text.rich(
TextSpan(
text: chatSessionTitle(session),
children: [
if (session['starred'] == true)
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Padding(
padding: const EdgeInsetsDirectional.only(start: 4),
child: _Star(cupertino: cupertino, color: accent),
),
),
],
),
),
timeWidget: updatedAt == null
? null
: RelativeTimeLabel(instant: updatedAt),
// `Closed` leads the line of a closed chat, then the model and folder.
subtitle: Text.rich(
TextSpan(
children: [
if (closed)
const TextSpan(
text: 'Closed',
style: TextStyle(fontWeight: FontWeight.w600),
),
if (closed && text.isNotEmpty) const TextSpan(text: ' · '),
TextSpan(text: text),
],
),
),
subtitleTrailing: unread
? AppListStatusDot(
key: const Key('chat-row-unread'),
color: accent,
semanticLabel: 'New',
size: 10,
)
: null,
menu: SessionActionsButton(
key: Key('chat-actions-$id'),
session: session,
duplicateTitles: duplicateTitles,
onSelected: onAction,
),
);
}
}
DateTime? _chatSessionInstant(Object? updatedAt) {
final millis = chatSessionMillis(updatedAt);
return millis <= 0 ? null : DateTime.fromMillisecondsSinceEpoch(millis);
}
/// As tall as the title's text, so it follows text scaling.
class _Star extends StatelessWidget {
const _Star({required this.cupertino, required this.color});
final bool cupertino;
final Color color;
@override
Widget build(BuildContext context) {
final size = DefaultTextStyle.of(context).style.fontSize ?? 14;
return Icon(
cupertino ? CupertinoIcons.star_fill : Icons.star,
key: const Key('chat-row-starred'),
size: MediaQuery.textScalerOf(context).scale(size),
color: color,
semanticLabel: 'Starred',
);
}
}
/// The chat's harness mark in a filled circle, like a contact avatar. A
/// running chat carries a small activity badge on the avatar's corner instead
/// of a line of its own; a selected chat's avatar takes the accent fill.
class ChatSessionAvatar extends StatelessWidget {
const ChatSessionAvatar({
super.key,
required this.session,
this.running = false,
this.selected = false,
});
final JsonMap session;
final bool running;
final bool selected;
@override
Widget build(BuildContext context) {
final cupertino =
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
final Color fill;
final Color mark;
final color = chatColorShade(context, chatSessionColor(session));
if (color != null) {
// The chat's colour is its identity, selected or not; the row's own
// fill marks the selection.
mark = color;
fill = color.withValues(
alpha: chatColorDarkSurface(context) ? 0.26 : 0.16,
);
} else if (cupertino) {
final primary = CupertinoTheme.of(context).primaryColor;
fill = selected
? primary.withValues(alpha: 0.2)
: CupertinoColors.systemGrey5.resolveFrom(context);
mark = selected ? primary : CupertinoColors.label.resolveFrom(context);
} else {
final scheme = Theme.of(context).colorScheme;
fill = selected
? scheme.primaryContainer
: scheme.surfaceContainerHighest;
mark = selected ? scheme.onPrimaryContainer : scheme.onSurfaceVariant;
}
return AppListAvatar(
foreground: mark,
background: fill,
badge: running
? Semantics(
key: const Key('chat-row-working'),
label: 'Chat is working',
child: _WorkingBadge(cupertino: cupertino),
)
: null,
child: SessionHarnessIcon(session: session, color: mark),
);
}
}
class _WorkingBadge extends StatelessWidget {
const _WorkingBadge({required this.cupertino});
final bool cupertino;
@override
Widget build(BuildContext context) {
final background = cupertino
? CupertinoColors.systemBackground.resolveFrom(context)
: Theme.of(context).colorScheme.surface;
return DecoratedBox(
decoration: BoxDecoration(color: background, shape: BoxShape.circle),
child: Padding(
padding: const EdgeInsets.all(2),
child: cupertino
? const CupertinoActivityIndicator(radius: 6)
: const SizedBox.square(
dimension: 12,
child: CircularProgressIndicator(strokeWidth: 2),
),
),
);
}
}