d1ffa7c79b
Follow the web chat layout on both hosts without changing request shapes or
bubble/composer behaviour.
- Session rows (Material and Cupertino): title with trailing relative
recency, muted `directory · model` line with the `New`/`Closed` word at
the trailing edge. Shared row content keeps one arrangement; native tiles
keep their own padding, separators and subtitle size. The state word keeps
its intrinsic width and the metadata ellipsises first, so it is never
clipped at 320px/2x.
- Thread header: one row of compact icon-only Back, ellipsised title,
bounded model control and Chat information. Back keeps the destination as
its accessible name and both hosts share `Key('chat-back')`.
- Share the epoch-millis parser as `chatSessionMillis`, and match the web's
relative-time words, including `Sept`.
- Cover the row content, status word at narrow widths, header layout and
Back accessibility in widget tests; update existing tests for the
separate trailing status word.
93 lines
3.3 KiB
Dart
93 lines
3.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../core/api_gateway.dart';
|
|
import '../../domain/chat_sessions.dart';
|
|
|
|
/// Titles shared by more than one visible session, so row action labels can
|
|
/// add the session id the way the web client does.
|
|
Set<String> duplicateChatTitles(Iterable<JsonMap> sessions) {
|
|
final seen = <String>{};
|
|
final duplicates = <String>{};
|
|
for (final session in sessions) {
|
|
final title = chatSessionTitle(session);
|
|
if (!seen.add(title)) duplicates.add(title);
|
|
}
|
|
return duplicates;
|
|
}
|
|
|
|
String sessionActionsLabel(JsonMap session, Set<String> duplicateTitles) {
|
|
final title = chatSessionTitle(session);
|
|
return duplicateTitles.contains(title)
|
|
? 'Chat actions for $title (${session['id'] ?? ''})'
|
|
: 'Chat actions for $title';
|
|
}
|
|
|
|
/// The web row's relative recency: `just now`, `N min ago`, `N hr ago`,
|
|
/// `N days ago`, then a short date (`22 Oct`). A row without a usable
|
|
/// `updated_at` reports nothing rather than inventing a time.
|
|
String relativeChatSessionTime(Object? updatedAt, {DateTime? now}) {
|
|
final millis = chatSessionMillis(updatedAt);
|
|
if (millis <= 0) return '';
|
|
final then = DateTime.fromMillisecondsSinceEpoch(millis);
|
|
var elapsed = (now ?? DateTime.now()).difference(then);
|
|
if (elapsed.isNegative) elapsed = Duration.zero;
|
|
final seconds = elapsed.inSeconds;
|
|
if (seconds < 45) return 'just now';
|
|
final minutes = seconds ~/ 60 < 1 ? 1 : seconds ~/ 60;
|
|
if (minutes < 60) return '$minutes min ago';
|
|
final hours = minutes ~/ 60;
|
|
if (hours < 24) return '$hours hr ago';
|
|
final days = hours ~/ 24;
|
|
if (days < 7) return days == 1 ? '1 day ago' : '$days days ago';
|
|
return '${then.day} ${_shortMonths[then.month - 1]}';
|
|
}
|
|
|
|
/// The row's muted second line: the directory the chat runs in, plus the model
|
|
/// the server recorded for it. Both come from the row; nothing is inferred.
|
|
String chatSessionMeta(JsonMap session) => [
|
|
'${session['directory'] ?? ''}'.trim(),
|
|
'${session['model'] ?? ''}'.trim(),
|
|
].where((part) => part.isNotEmpty).join(' · ');
|
|
|
|
/// The word on the row's trailing edge while the session has news or a state:
|
|
/// `Closed` from the row, otherwise `New`. A streaming session deliberately
|
|
/// says nothing, as on the web, where the row's activity logo carries it.
|
|
String? chatSessionRowStatus(JsonMap session, {required bool unseen}) {
|
|
if (session['closed_at'] != null || session['closed'] == true) {
|
|
return 'Closed';
|
|
}
|
|
// Streaming has no word, as on the web; the row's activity icon carries it.
|
|
if (session['running'] == true) return null;
|
|
return unseen ? 'New' : null;
|
|
}
|
|
|
|
const _shortMonths = [
|
|
'Jan',
|
|
'Feb',
|
|
'Mar',
|
|
'Apr',
|
|
'May',
|
|
'Jun',
|
|
'Jul',
|
|
'Aug',
|
|
// `Intl.DateTimeFormat('en-GB', { month: 'short' })`, which the web row
|
|
// uses, abbreviates September as `Sept`, not `Sep`.
|
|
'Sept',
|
|
'Oct',
|
|
'Nov',
|
|
'Dec',
|
|
];
|
|
|
|
IconData sessionMaterialIcon(JsonMap session) {
|
|
if (session['running'] == true) return Icons.sync;
|
|
if (session['starred'] == true) return Icons.star;
|
|
return Icons.chat_bubble_outline;
|
|
}
|
|
|
|
IconData sessionCupertinoIcon(JsonMap session) {
|
|
if (session['running'] == true) return CupertinoIcons.arrow_2_circlepath;
|
|
if (session['starred'] == true) return CupertinoIcons.star_fill;
|
|
return CupertinoIcons.chat_bubble;
|
|
}
|