Files
pipelines/app/lib/features/chat/ui/sessions/session_activity_badge.dart
T
alan 4c82a9637e Show loudly in the chat list when a chat is waiting on the operator
The server's chat activity now counts each session's unanswered
approvals and questions (awaiting_operator) and pushes it to every
connection when it changes. A waiting chat's list row pulses in the
error colour with a solid bar on its leading edge, its avatar wears a
ringing bell in place of the spinner, and its state line leads with a
bold "Waiting for you". Reduced motion holds the pulse and the bell
still.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 22:54:38 +00:00

86 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
import '../../../../ui/status/app_spinner.dart';
import 'chat_awaiting.dart';
/// The corner badge a chat's avatar wears for its live activity: the
/// platform's activity indicator while a turn runs; otherwise, while
/// background tasks still run, a quiet muted glyph (never a second spinner).
/// Null when the chat is idle.
Widget? chatSessionActivityBadge({
required bool running,
required int backgroundTasks,
int awaitingOperator = 0,
}) {
// Waiting on the operator outranks everything: the agent is blocked.
if (awaitingOperator > 0) return ChatAwaitingBadge(count: awaitingOperator);
if (running) {
return Semantics(
key: const Key('chat-row-working'),
label: 'Chat is working',
child: const _WorkingBadge(),
);
}
if (backgroundTasks <= 0) return null;
final label = 'Background tasks running ($backgroundTasks)';
// Hover shows the tooltip on a pointer device; a touch long press stays the
// row's own gesture.
return Tooltip(
key: const Key('chat-row-background'),
message: label,
triggerMode: TooltipTriggerMode.manual,
excludeFromSemantics: true,
child: Semantics(
label: label,
child: _BackgroundBadge(count: backgroundTasks),
),
);
}
/// The badge's own disc in the surface colour, so it reads over any avatar.
class _BadgeDisc extends StatelessWidget {
const _BadgeDisc({required this.child});
final Widget child;
@override
Widget build(BuildContext context) {
final background = Theme.of(context).colorScheme.surface;
return DecoratedBox(
decoration: BoxDecoration(color: background, shape: BoxShape.circle),
child: Padding(padding: const EdgeInsets.all(2), child: child),
);
}
}
class _WorkingBadge extends StatelessWidget {
const _WorkingBadge();
@override
Widget build(BuildContext context) {
return const _BadgeDisc(
child: SizedBox.square(dimension: 12, child: AppSpinner(strokeWidth: 2)),
);
}
}
class _BackgroundBadge extends StatelessWidget {
const _BackgroundBadge({required this.count});
final int count;
@override
Widget build(BuildContext context) {
final color = Theme.of(context).colorScheme.onSurfaceVariant;
return _BadgeDisc(
child: Text(
'$count',
style: TextStyle(
color: color,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
);
}
}