4c82a9637e
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>
167 lines
4.6 KiB
Dart
167 lines
4.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// How a chat that is waiting on the operator (an unanswered approval or
|
|
/// question; the agent is blocked until they reply) stands out in the chat
|
|
/// list: a ringing bell on the avatar, and a pulsing error-coloured row with a
|
|
/// solid bar on its leading edge. With reduced motion both hold still.
|
|
|
|
/// The accessible name of a waiting chat's bell.
|
|
String chatAwaitingLabel(int count) => count == 1
|
|
? 'Waiting for your reply'
|
|
: 'Waiting for your reply ($count requests)';
|
|
|
|
/// The bell badge a waiting chat's avatar wears in place of the spinner.
|
|
class ChatAwaitingBadge extends StatefulWidget {
|
|
const ChatAwaitingBadge({super.key, required this.count});
|
|
|
|
final int count;
|
|
|
|
@override
|
|
State<ChatAwaitingBadge> createState() => _ChatAwaitingBadgeState();
|
|
}
|
|
|
|
class _ChatAwaitingBadgeState extends State<ChatAwaitingBadge>
|
|
with SingleTickerProviderStateMixin {
|
|
late final AnimationController _ring = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 1400),
|
|
);
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
final still = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
|
if (still) {
|
|
_ring.stop();
|
|
_ring.value = 0;
|
|
} else if (!_ring.isAnimating) {
|
|
_ring.repeat();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_ring.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final scheme = Theme.of(context).colorScheme;
|
|
return Semantics(
|
|
key: const Key('chat-row-awaiting'),
|
|
label: chatAwaitingLabel(widget.count),
|
|
child: DecoratedBox(
|
|
decoration: BoxDecoration(
|
|
color: scheme.error,
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: scheme.surface, width: 2),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(2),
|
|
child: AnimatedBuilder(
|
|
animation: _ring,
|
|
// A bell rings in short swings, then rests for the rest of the beat.
|
|
builder: (context, child) {
|
|
final t = _ring.value;
|
|
final swing = t < 0.4
|
|
? 0.45 * (1 - t / 0.4) * (t * 10 % 2 < 1 ? 1 : -1)
|
|
: 0.0;
|
|
return Transform.rotate(angle: swing, child: child);
|
|
},
|
|
child: Icon(
|
|
Icons.notifications_active,
|
|
size: 18,
|
|
color: scheme.onError,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The waiting chat's row: a pulsing error-container tint and a solid error
|
|
/// bar on the leading edge, over the row's own content.
|
|
class ChatAwaitingHighlight extends StatefulWidget {
|
|
const ChatAwaitingHighlight({
|
|
super.key,
|
|
required this.waiting,
|
|
required this.child,
|
|
});
|
|
|
|
final bool waiting;
|
|
final Widget child;
|
|
|
|
@override
|
|
State<ChatAwaitingHighlight> createState() => _ChatAwaitingHighlightState();
|
|
}
|
|
|
|
class _ChatAwaitingHighlightState extends State<ChatAwaitingHighlight>
|
|
with SingleTickerProviderStateMixin {
|
|
late final AnimationController _pulse = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 1100),
|
|
);
|
|
bool _still = false;
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
_still = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
|
_sync();
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(ChatAwaitingHighlight oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
_sync();
|
|
}
|
|
|
|
void _sync() {
|
|
if (widget.waiting && !_still) {
|
|
if (!_pulse.isAnimating) _pulse.repeat(reverse: true);
|
|
} else {
|
|
_pulse.stop();
|
|
_pulse.value = 1;
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_pulse.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (!widget.waiting) return widget.child;
|
|
final scheme = Theme.of(context).colorScheme;
|
|
return Stack(
|
|
children: [
|
|
Positioned.fill(
|
|
child: IgnorePointer(
|
|
child: RepaintBoundary(
|
|
child: AnimatedBuilder(
|
|
animation: _pulse,
|
|
builder: (context, _) => DecoratedBox(
|
|
key: const Key('chat-row-awaiting-highlight'),
|
|
decoration: BoxDecoration(
|
|
color: scheme.errorContainer.withValues(
|
|
alpha: 0.35 + 0.45 * _pulse.value,
|
|
),
|
|
border: BorderDirectional(
|
|
start: BorderSide(color: scheme.error, width: 5),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
widget.child,
|
|
],
|
|
);
|
|
}
|
|
}
|