Files
pipelines/app/lib/features/chat/ui/sessions/chat_compact_sidebar.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

210 lines
6.6 KiB
Dart

import '../../../../core/servers/chat/federated_chat_gateway.dart';
import '../../../../core/servers/server_context.dart';
import 'dart:async';
import 'package:flutter/material.dart';
import '../../../../core/api_gateway.dart';
import '../../domain/chat_cycle.dart';
import '../../domain/chat_sessions.dart';
import '../../domain/chat_colors.dart';
import 'chat_color_palette.dart';
import 'chat_visibility_marker.dart';
import 'chat_compact_avatar.dart';
import 'session_row_style.dart';
import '../../domain/chat_list_activity.dart';
import 'chat_sessions_body.dart';
import 'chat_sessions_controller.dart';
/// A small, scrollable device-local rail. Full titles remain accessible.
class ChatCompactSidebar extends StatelessWidget {
const ChatCompactSidebar({
super.key,
required this.controller,
required this.folds,
required this.activeSessionId,
this.visibleSessionIds = const {},
required this.onOpen,
required this.onNewChat,
required this.onExpand,
this.navigation,
});
final ChatSessionsController controller;
final ChatSectionFolds folds;
final String? activeSessionId;
final Set<String> visibleSessionIds;
final ValueChanged<JsonMap> onOpen;
final VoidCallback onNewChat;
final VoidCallback onExpand;
final Widget? navigation;
static const width = 72.0;
Widget _button(
BuildContext context,
String title,
Widget icon,
VoidCallback onPressed, {
bool selected = false,
}) {
return Semantics(
label: title,
button: true,
selected: selected,
onTap: onPressed,
excludeSemantics: true,
child: IconButton(
tooltip: title,
onPressed: onPressed,
icon: icon,
color: selected ? Theme.of(context).colorScheme.primary : null,
),
);
}
Widget _session(BuildContext context, JsonMap row) {
final id = '${row['id'] ?? ''}';
final selected = id == activeSessionId;
final visible = visibleSessionIds.contains(id);
final unread = controller.isUnseen(row);
final running = row['running'] == true;
final backgroundTasks = chatSessionBackgroundTasks(row);
final awaitingOperator = chatSessionAwaitingOperator(row);
final title = chatSessionTitle(row);
final machineName =
ServerContext.nameFor(context, '${row['_server_id'] ?? ''}') ??
row['_server_name'] as String?;
final details = [
title,
?(machineName ?? ServerContext.maybeOf(context)?.name),
if (chatSessionSubtitle(row).isNotEmpty) chatSessionSubtitle(row),
if (relativeChatSessionTime(row['updated_at']).isNotEmpty)
'Updated ${relativeChatSessionTime(row['updated_at'])} ago',
if (selected) 'Active chat' else if (visible) 'Visible chat',
if (running) 'Working',
if (backgroundTasks > 0) 'Background tasks running ($backgroundTasks)',
if (unread) 'New messages',
].join('\n');
final color =
chatColorShade(context, chatSessionColor(row)) ??
Theme.of(context).colorScheme.primary;
final button = _button(
context,
details,
ExcludeSemantics(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ChatCompactAvatar(
title: title,
color: color,
active: selected,
visible: visible,
running: running,
awaitingOperator: awaitingOperator,
backgroundTasks: backgroundTasks,
unread: unread,
),
if (machineName case final name?)
Text(
name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.labelSmall,
),
],
),
),
() {
unawaited(controller.markOpened(row));
onOpen(row);
},
selected: selected,
);
return ChatVisibilityMarker(
sessionId: id,
color: color,
visible: visible,
active: selected,
child: AnimatedContainer(
duration: MediaQuery.disableAnimationsOf(context)
? Duration.zero
: const Duration(milliseconds: 200),
color: selected ? Colors.transparent : color.withValues(alpha: .07),
child: Draggable<JsonMap>(
// A mouse drags at once (a click still opens the chat); the chip
// follows the pointer.
dragAnchorStrategy: pointerDragAnchorStrategy,
data: row,
feedback: Material(
elevation: 4,
borderRadius: BorderRadius.circular(20),
child: Chip(
avatar: ChatCompactAvatar(
title: title,
color: color,
active: false,
visible: false,
running: running,
awaitingOperator: awaitingOperator,
backgroundTasks: backgroundTasks,
unread: unread,
),
label: Text(title),
),
),
childWhenDragging: Opacity(opacity: .35, child: button),
child: button,
),
),
);
}
@override
Widget build(BuildContext context) => Align(
alignment: AlignmentDirectional.topStart,
child: SizedBox(
width: width,
child: Column(
children: [
_button(context, 'New chat', const Icon(Icons.add), onNewChat),
_button(
context,
'Expand chat list',
Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.menu_open),
const Text('Expand', textAlign: TextAlign.center),
if (controller.repository.gateway is FederatedChatGateway)
const Text('All machines', textAlign: TextAlign.center)
else if (ServerContext.maybeOf(context)?.name case final name?)
Text(
name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
),
],
),
onExpand,
),
Expanded(
child: ListenableBuilder(
listenable: Listenable.merge([controller, folds]),
builder: (context, _) {
final rows = chatSessionsShown(
controller.sessions,
query: '',
isOpen: folds.isOpen,
);
return ListView(
children: [for (final row in rows) _session(context, row)],
);
},
),
),
?navigation,
],
),
),
);
}