45c933c176
The list applies chat_activity pushes and each row's activity by seq, so every listed chat shows a running turn, not only the chat open here. An idle chat with running background tasks wears a quiet badge with tooltip and semantics "Background tasks running (N)". Older servers keep the old behaviour. List rows that never changed carry the server's current seq so they order after snapshots kept from an earlier server process.
94 lines
2.7 KiB
Dart
94 lines
2.7 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.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 cupertino,
|
|
required bool running,
|
|
required int backgroundTasks,
|
|
}) {
|
|
if (running) {
|
|
return Semantics(
|
|
key: const Key('chat-row-working'),
|
|
label: 'Chat is working',
|
|
child: _WorkingBadge(cupertino: cupertino),
|
|
);
|
|
}
|
|
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(cupertino: cupertino),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// The badge's own disc in the surface colour, so it reads over any avatar.
|
|
class _BadgeDisc extends StatelessWidget {
|
|
const _BadgeDisc({required this.cupertino, required this.child});
|
|
|
|
final bool cupertino;
|
|
final Widget child;
|
|
|
|
@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: child),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _WorkingBadge extends StatelessWidget {
|
|
const _WorkingBadge({required this.cupertino});
|
|
|
|
final bool cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return _BadgeDisc(
|
|
cupertino: cupertino,
|
|
child: cupertino
|
|
? const CupertinoActivityIndicator(radius: 6)
|
|
: const SizedBox.square(
|
|
dimension: 12,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _BackgroundBadge extends StatelessWidget {
|
|
const _BackgroundBadge({required this.cupertino});
|
|
|
|
final bool cupertino;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final color = cupertino
|
|
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.onSurfaceVariant;
|
|
return _BadgeDisc(
|
|
cupertino: cupertino,
|
|
child: Icon(
|
|
cupertino ? CupertinoIcons.ellipsis_circle_fill : Icons.pending,
|
|
size: 12,
|
|
color: color,
|
|
),
|
|
);
|
|
}
|
|
}
|