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

+30 -9
View File
@@ -10,6 +10,7 @@ import '../widgets/composer_attachment.dart';
import '../widgets/composer_box.dart';
import '../widgets/model_controls.dart';
import '../widgets/pet_sprite.dart';
import '../widgets/project_icon.dart';
import '../widgets/slash_palette.dart';
import 'files_panel.dart';
@@ -280,6 +281,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
Widget _projectChip(SessionDraft draft) {
final theme = Theme.of(context);
final isChat = draft.directory == AppState.chatTarget;
final label = widget.app.projectLabelFor(draft.directory);
return InkWell(
borderRadius: BorderRadius.circular(18),
@@ -289,8 +291,12 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.folder_outlined,
size: 15, color: theme.hintColor),
ProjectIcon(
app: widget.app,
project: isChat ? null : widget.app.projectFor(draft.directory),
chat: isChat,
size: 15,
),
const SizedBox(width: 5),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 170),
@@ -455,7 +461,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
Future<void> _pickProject() async {
final app = widget.app;
await app.refreshProjects();
await Future.wait([app.refreshProjects(), app.refreshFsHome()]);
if (!mounted) return;
final draft = app.draft;
if (draft == null) return;
@@ -479,14 +485,29 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
child: ListView(
controller: controller,
children: [
ListTile(
dense: true,
leading: ProjectIcon(
app: widget.app, chat: true, size: 20),
title: const Text('聊天'),
subtitle: const Text('不关联项目,保存在 OpenChamber 的聊天目录'),
trailing: draft.directory == AppState.chatTarget
? Icon(Icons.check,
size: 18,
color: Theme.of(context).colorScheme.primary)
: null,
onTap: () {
app.updateDraftTarget(AppState.chatTarget);
_slashLoaded = false;
_slashItems = [];
Navigator.pop(context);
},
),
for (final project in projects)
ListTile(
dense: true,
leading: Icon(
project.vcs.isNotEmpty
? Icons.account_tree_outlined
: Icons.folder_outlined,
size: 20),
leading:
ProjectIcon(app: widget.app, project: project, size: 20),
title: Text(project.label,
maxLines: 1, overflow: TextOverflow.ellipsis),
subtitle: Text(project.canonical,
@@ -525,7 +546,7 @@ class _NewSessionScreenState extends State<NewSessionScreen> {
final byPath = <String, ProjectInfo>{};
for (final project in projects) {
if (project.canonical.isEmpty) continue;
if (project.canonical.contains('/.config/openchamber/')) continue;
if (widget.app.isChatDirectory(project.canonical)) continue;
final existing = byPath[project.canonical];
if (existing == null ||
(existing.vcs.isEmpty && project.vcs.isNotEmpty)) {
+22 -13
View File
@@ -6,6 +6,7 @@ import 'package:flutter_slidable/flutter_slidable.dart';
import '../api/models.dart';
import '../state.dart';
import '../widgets/project_icon.dart';
import 'servers_screen.dart';
import 'settings_screen.dart';
@@ -248,19 +249,13 @@ class _SessionListPaneState extends State<SessionListPane> {
// --------------------------------------------------------------- groups
bool _isChatDirectory(String directory) =>
directory.contains('/.config/openchamber/chats');
String _groupLabel(String key) =>
key == '\u0000chats' ? '聊天' : _app.projectLabelFor(key);
List<_SessionGroup> _groups(List<Session> sessions) {
final map = <String, List<Session>>{};
for (final session in sessions) {
// Group on a separator-normalised key so a Windows server's mix of
// `\` and `/` does not split one project into two.
final key = _isChatDirectory(session.directory)
? '\u0000chats'
final key = _app.isChatDirectory(session.directory)
? AppState.chatTarget
: slashPath(session.directory);
map.putIfAbsent(key, () => []).add(session);
}
@@ -268,9 +263,13 @@ class _SessionListPaneState extends State<SessionListPane> {
for (final entry in map.entries)
_SessionGroup(
key: entry.key,
label: _groupLabel(entry.value.first.directory),
label: entry.key == AppState.chatTarget
? '聊天'
: _app.projectLabelFor(entry.value.first.directory),
// The first session's own path: the server knows that spelling.
path: entry.key == '\u0000chats' ? '' : entry.value.first.directory,
path: entry.key == AppState.chatTarget
? ''
: entry.value.first.directory,
sessions: entry.value
..sort((a, b) => b.updated.compareTo(a.updated)),
),
@@ -320,7 +319,14 @@ class _SessionListPaneState extends State<SessionListPane> {
Icon(collapsed ? Icons.chevron_right : Icons.expand_more,
size: 18, color: scheme.onSurfaceVariant),
const SizedBox(width: 2),
Icon(Icons.folder_outlined, size: 16, color: scheme.primary),
ProjectIcon(
app: _app,
project: group.key == AppState.chatTarget
? null
: _app.projectFor(group.path),
chat: group.key == AppState.chatTarget,
size: 16,
),
],
),
title: Text(
@@ -349,8 +355,11 @@ class _SessionListPaneState extends State<SessionListPane> {
child: IconButton(
icon: const Icon(Icons.add, size: 20),
padding: EdgeInsets.zero,
tooltip: '在此项目新会话',
onPressed: () => _newSession(directory: group.path),
tooltip: group.key == AppState.chatTarget ? '新建聊天' : '在此项目新会话',
onPressed: () => _newSession(
directory: group.key == AppState.chatTarget
? AppState.chatTarget
: group.path),
),
),
onTap: () => setState(() {