App: chat colours, Ctrl+1-9 opens the Nth list item, starred chats alphabetical
A chat's colour is picked from its row menu (Colour...), a long-press or the chat information sheet. The list shows it as a leading bar, a faint row tint and a coloured avatar; the open chat shows a faint wash under its top bar. Shades are Cupertino's dynamic system colours and Material swatches tuned per brightness. Changes from other devices apply live. Ctrl+1...Ctrl+9 open the Nth item of the open tab's list (chats, runs, pipelines) in on-screen order, also while typing. Starred chats are sorted by name, case-insensitively, as one alphabetical group.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/// The fixed palette of shared chat highlight colours, by the names the
|
||||
/// server stores, in picker order. Each host renders its own tuned shade.
|
||||
const chatColorNames = [
|
||||
'red',
|
||||
'orange',
|
||||
'amber',
|
||||
'green',
|
||||
'teal',
|
||||
'blue',
|
||||
'purple',
|
||||
'pink',
|
||||
];
|
||||
|
||||
/// The session's highlight name, or null when it has none (or one this
|
||||
/// client does not know).
|
||||
String? chatSessionColor(Map<String, dynamic>? session) {
|
||||
final name = '${session?['color'] ?? ''}'.trim();
|
||||
return chatColorNames.contains(name) ? name : null;
|
||||
}
|
||||
|
||||
/// The colour's name as a person reads it.
|
||||
String chatColorLabel(String name) =>
|
||||
name.isEmpty ? name : name[0].toUpperCase() + name.substring(1);
|
||||
@@ -34,6 +34,62 @@ List<({String directory, List<JsonMap> sessions})> groupChatSessions(
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// The list's sections in on-screen order: Starred (open chats, by name, so
|
||||
/// each keeps its place), Chats (open, server recency) and Closed (server
|
||||
/// recency). Empty sections are left out.
|
||||
List<({String title, List<JsonMap> sessions})> chatSessionSections(
|
||||
List<JsonMap> visible,
|
||||
) {
|
||||
bool closed(JsonMap s) => s['closed_at'] != null;
|
||||
bool starred(JsonMap s) => s['starred'] == true && !closed(s);
|
||||
final sections = [
|
||||
(
|
||||
title: 'Starred',
|
||||
sessions: sortStarredChatSessions(visible.where(starred)),
|
||||
),
|
||||
(
|
||||
title: 'Chats',
|
||||
sessions: visible.where((s) => !starred(s) && !closed(s)).toList(),
|
||||
),
|
||||
(title: 'Closed', sessions: visible.where(closed).toList()),
|
||||
];
|
||||
return [
|
||||
for (final section in sections)
|
||||
if (section.sessions.isNotEmpty) section,
|
||||
];
|
||||
}
|
||||
|
||||
/// Starred chats alphabetically by their shown title, ignoring case; equal
|
||||
/// titles keep a fixed order by id.
|
||||
List<JsonMap> sortStarredChatSessions(Iterable<JsonMap> sessions) =>
|
||||
sessions.toList()..sort((a, b) {
|
||||
final byTitle = chatSessionTitle(
|
||||
a,
|
||||
).toLowerCase().compareTo(chatSessionTitle(b).toLowerCase());
|
||||
if (byTitle != 0) return byTitle;
|
||||
return '${a['id'] ?? ''}'.compareTo('${b['id'] ?? ''}');
|
||||
});
|
||||
|
||||
/// Whether a section's rows are split under directory headings. Starred keeps
|
||||
/// its alphabetical order whole, so a name is always in the same place.
|
||||
bool chatSectionGroupsByDirectory(String title) => title != 'Starred';
|
||||
|
||||
/// The rows of [sections] in the order the list draws them: each open
|
||||
/// section's rows, directory group by directory group. A folded section
|
||||
/// draws no rows.
|
||||
List<JsonMap> chatSessionsInListOrder(
|
||||
List<({String title, List<JsonMap> sessions})> sections, {
|
||||
required bool Function(String title) isOpen,
|
||||
}) => [
|
||||
for (final section in sections)
|
||||
if (isOpen(section.title))
|
||||
if (chatSectionGroupsByDirectory(section.title))
|
||||
for (final group in groupChatSessions(section.sessions))
|
||||
...group.sessions
|
||||
else
|
||||
...section.sessions,
|
||||
];
|
||||
|
||||
String chatSessionActivity({required bool running, required bool unseen}) =>
|
||||
running
|
||||
? 'streaming'
|
||||
|
||||
Reference in New Issue
Block a user