feat: group the server's chats and use OpenChamber's project icons

Sessions under the server's managed chats root (chats/<date>/session-…) were
grouped per directory, so each one appeared as its own session-xxxxx band.
GET /api/fs/home now supplies the chats root plus its canonical and legacy
aliases; every chat folder becomes the single 聊天 group. The new-session
picker can target 聊天 too: the first send creates a fresh chat directory
before creating the session, and a new session started from an existing chat
gets a new one instead of sharing its folder.

Projects merge their OpenChamber settings row (label, icon key, colour,
iconBackground and uploaded/auto icon image) with /api/project. Group
headers, the picker and the draft chip draw the chosen icon in its colour,
and custom images are fetched through the client transport (SVG included)
with a themed fallback to the glyph. The chat group uses a chat bubble rather
than a folder.

0.4.8 (408).
This commit is contained in:
blumia committed 2026-11-23 17:42:49 +08:00
1 parent 91bf5e5b81
commit 79221e57d7
14 files changed
+599 -32

No files matched your search

+12
View File
@@ -30,4 +30,16 @@ void main() {
test('slashPath only unifies separators', () {
expect(slashPath(r'C:\a\b\'), 'C:/a/b');
});
test('a directory is recognised under a chats root', () {
expect(isUnderDirectory('/home/me/.config/openchamber/chats/2026-11-23/x',
'/home/me/.config/openchamber/chats'), isTrue);
expect(isUnderDirectory(r'C:\Users\me\.config\openchamber\chats\a\b',
r'c:\users\me\.config\openchamber\chats'), isTrue);
expect(isUnderDirectory('/home/me/.config/openchamber/chats-other/x',
'/home/me/.config/openchamber/chats'), isFalse);
expect(isUnderDirectory('/home/me/project', '/home/me/.config/openchamber/chats'),
isFalse);
expect(isUnderDirectory('', '/x'), isFalse);
});
}
+46
View File
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:openchamber/api/models.dart';
import 'package:openchamber/widgets/project_icon.dart';
void main() {
test('OpenChamber icon keys map to Flutter icons', () {
expect(projectIconData('code'), Icons.code);
expect(projectIconData('terminal'), Icons.terminal);
expect(projectIconData('ai'), Icons.psychology_outlined);
expect(projectIconData('unknown'), isNull);
expect(projectIconData(''), isNull);
});
test('hex and legacy project colours resolve', () {
final scheme = ColorScheme.fromSeed(seedColor: Colors.indigo);
expect(projectHexColor('#30a46c'), const Color(0xff30a46c));
expect(projectHexColor('#abc'), const Color(0xffaabbcc));
expect(projectHexColor('30a46c'), isNull);
expect(projectColor('error', scheme), scheme.error);
expect(projectColor('primary', scheme), scheme.primary);
expect(projectColor('comment', scheme), scheme.onSurfaceVariant);
expect(projectColor('#30a46c', scheme), const Color(0xff30a46c));
expect(projectColor('', scheme), isNull);
});
test('a settings row decorates the project with label and icon metadata', () {
const project = ProjectInfo(id: 'p1', canonical: '/w/app');
final merged = project.withMeta({
'id': 'path_L3cL2FwcA',
'path': '/w/app',
'label': 'My App',
'icon': 'rocket',
'color': '#30a46c',
'iconBackground': '#101010',
'iconImage': {'mime': 'image/svg+xml', 'updatedAt': 42},
});
expect(merged.label, 'My App');
expect(merged.icon, 'rocket');
expect(merged.color, '#30a46c');
expect(merged.metaId, 'path_L3cL2FwcA');
expect(merged.hasIconImage, isTrue);
expect(merged.iconImageMime, 'image/svg+xml');
expect(merged.iconImageUpdatedAt, 42);
});
}
+38
View File
@@ -5,6 +5,44 @@ import 'package:openchamber/screens/sessions_screen.dart';
import 'package:openchamber/state.dart';
void main() {
testWidgets('chat folders group under 聊天, not under session-xxxxx',
(tester) async {
final app = AppState();
app.chatRoots = const [r'C:\Users\me\.config\openchamber\chats'];
final now = DateTime.now().millisecondsSinceEpoch;
app.sessions = [
Session(
id: 'c1',
title: 'OpenCode 图像模型配置',
location: Location(
r'C:\Users\me\.config\openchamber\chats\2026-11-23\session-a'),
created: now,
updated: now,
),
Session(
id: 'c2',
title: 'LC_ALL 环境变量的设置来源',
location: Location(
r'C:\Users\me\.config\openchamber\chats\2026-11-22\session-b'),
created: now - 1000,
updated: now - 1000,
),
];
addTearDown(app.dispose);
await tester.pumpWidget(MaterialApp(
home: Scaffold(body: SessionListPane(app: app)),
));
await tester.pumpAndSettle();
// One chats group, labelled the same as the first-party sidebar.
expect(find.text('聊天'), findsOneWidget);
expect(find.byTooltip('新建聊天'), findsOneWidget);
expect(find.textContaining('session-'), findsNothing);
expect(find.text('OpenCode 图像模型配置'), findsOneWidget);
expect(find.text('LC_ALL 环境变量的设置来源'), findsOneWidget);
});
testWidgets('the project band matches a session row and keeps the keys in line',
(tester) async {
final app = AppState();