9551eceaed
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
180 lines
5.7 KiB
Dart
180 lines
5.7 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.onExpand,
|
|
this.navigation,
|
|
});
|
|
final ChatSessionsController controller;
|
|
final ChatSectionFolds folds;
|
|
final String? activeSessionId;
|
|
final Set<String> visibleSessionIds;
|
|
final ValueChanged<JsonMap> onOpen;
|
|
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 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;
|
|
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: _button(
|
|
context,
|
|
details,
|
|
ExcludeSemantics(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
ChatCompactAvatar(
|
|
title: title,
|
|
color: color,
|
|
active: selected,
|
|
visible: visible,
|
|
running: running,
|
|
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,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Align(
|
|
alignment: AlignmentDirectional.topStart,
|
|
child: SizedBox(
|
|
width: width,
|
|
child: Column(
|
|
children: [
|
|
_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,
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|