Files
pipelines/app/lib/features/chat/ui/transcript/chat_message_timestamp.dart
T
alan a3a59adb30 Quieter transcript metadata: day dividers, time-only rows, muted meta rows
- Date once per calendar day: a muted centred divider above each day's
  first timed row (chatDayDividers); rows show only their time ("10:16"),
  with the full date and time kept in the tooltip and semantics. The user's
  time shares the delivery line; a harness notice's time trails its line.
- Activity line and turn chips are secondary: bodyMedium, regular weight,
  onSurfaceVariant (error colour kept for failures), a small chevron_right
  that turns down while its details are open (replaces expand_less).
- Copy / Read aloud: 18 px muted icons; on pointer devices shown only while
  the reply is hovered or an action is focused (also without the gutter);
  touch keeps them visible with a full tap target. The time leads the
  footer so hidden actions leave no gap.
- Settled questions: the question on one line, the operator's answer in
  full on its own line beneath it.
- Meta rows (activity, chips, notices, compaction line) start at the reply
  text's leading edge; turn chips sit in their own column under the answer.
- Scroll fixture: ?timestamps=1 spreads messages over two days.

Row keys are unchanged; the divider joins a row without replacing it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 11:10:51 +00:00

121 lines
3.7 KiB
Dart

import 'package:flutter/material.dart';
/// The local date as the transcript's day divider names it: `25 November 2026`.
String chatDayLabel(BuildContext context, DateTime day) =>
'${day.day} ${MaterialLocalizations.of(context).formatMonthYear(day)}';
/// The small, non-selectable time of a recorded chat message: `10:16`. The
/// date is named once per day by [ChatDayDivider]; the tooltip and semantics
/// still carry the full localized date and time.
class ChatMessageTimestamp extends StatelessWidget {
const ChatMessageTimestamp({super.key, required this.createdAt});
final int? createdAt;
@override
Widget build(BuildContext context) {
final instant = createdAt == null
? null
: DateTime.fromMillisecondsSinceEpoch(
createdAt!,
isUtc: true,
).toLocal();
if (instant == null) return const SizedBox.shrink();
final material = MaterialLocalizations.of(context);
final time = material.formatTimeOfDay(
TimeOfDay.fromDateTime(instant),
alwaysUse24HourFormat: true,
);
final full = '${chatDayLabel(context, instant)}, $time';
final style = chatMetaTextStyle(context);
return SelectionContainer.disabled(
child: Tooltip(
message: full,
child: Semantics(
container: true,
label: 'Sent $full',
excludeSemantics: true,
child: Text(time, style: style),
),
),
);
}
}
/// The muted small text of transcript metadata (times, the answering model).
TextStyle? chatMetaTextStyle(BuildContext context) => Theme.of(context)
.textTheme
.bodySmall
?.copyWith(color: Theme.of(context).colorScheme.onSurfaceVariant);
/// A transcript row with the [ChatDayDivider] for [day] above it when the row
/// starts a calendar day. The row keeps its element whether or not a divider
/// joins or leaves above it (an older page arriving moves the day's start).
class ChatDayDivided extends StatelessWidget {
const ChatDayDivided({
super.key,
required this.day,
required this.child,
this.inset = 0,
});
final DateTime? day;
/// Leading space before the divider, so it keeps to the reading column.
final double inset;
final Widget child;
@override
Widget build(BuildContext context) {
final day = this.day;
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (day != null)
Padding(
key: const ValueKey<String>('chat-day-divider'),
padding: EdgeInsetsDirectional.only(start: inset),
child: ChatDayDivider(day: day),
),
KeyedSubtree(key: const ValueKey<String>('chat-day-row'), child: child),
],
);
}
}
/// A quiet centred date between two thin rules, above the first message of
/// each calendar day in the transcript.
class ChatDayDivider extends StatelessWidget {
const ChatDayDivider({super.key, required this.day});
final DateTime day;
@override
Widget build(BuildContext context) {
final label = chatDayLabel(context, day);
return SelectionContainer.disabled(
child: Semantics(
container: true,
header: true,
label: label,
excludeSemantics: true,
child: Padding(
padding: const EdgeInsets.only(top: 12, bottom: 4),
child: Row(
children: [
const Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(label, style: chatMetaTextStyle(context)),
),
const Expanded(child: Divider()),
],
),
),
),
);
}
}