Fix stale map labels, avatar initials and offline bubble widths

- Map node labels follow light/dark theme changes.
- Avatar initials use only letters and digits; hop avatars fall back to the
  hash prefix.
- Incoming channel bubbles are the same width connected and offline.
- Day separators wrap instead of overflowing with large text.
This commit is contained in:
zjs81 committed 2026-11-20 16:04:50 -07:00
1 parent 34ea0cb7ca
commit 92dadb0d3a
12 files changed
+642 -48

No files matched your search

+27 -14
View File
@@ -44,21 +44,34 @@ class ChatDaySeparator extends StatelessWidget {
);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
children: [
line,
const SizedBox(width: 10),
Text(
formatChatDayLabel(context, day),
style: MeshTheme.mono(
fontSize: 12,
fontWeight: FontWeight.w600,
color: color,
child: LayoutBuilder(
// Large text on a narrow phone wraps the label instead of overflowing;
// each rule keeps at least 16dp.
builder: (context, constraints) => Row(
children: [
line,
const SizedBox(width: 10),
ConstrainedBox(
constraints: BoxConstraints(
maxWidth: (constraints.maxWidth - 2 * (10 + 16)).clamp(
0.0,
double.infinity,
),
),
child: Text(
formatChatDayLabel(context, day),
textAlign: TextAlign.center,
style: MeshTheme.mono(
fontSize: 12,
fontWeight: FontWeight.w600,
color: color,
),
),
),
),
const SizedBox(width: 10),
line,
],
const SizedBox(width: 10),
line,
],
),
),
);
}
+35
View File
@@ -5,6 +5,7 @@ import '../l10n/app_localizations.dart';
import '../models/contact.dart';
import '../theme/mesh_theme.dart';
import '../theme/theme_icons.dart';
import '../utils/emoji_utils.dart';
/// Shared node-type visuals and last-seen formatting for contact lists
/// (contacts, discovery, nearby-node scan).
@@ -41,6 +42,40 @@ ThemeIconSlot? contactTypeIconSlot(int type) {
}
}
final RegExp _letterOrDigit = RegExp(r'^[\p{L}\p{N}]', unicode: true);
/// Avatar initials for a display name, or null when the name has nothing
/// usable so the caller can show an icon or key prefix instead.
///
/// Only letters and digits count: punctuation such as `-`, `(` or `[` splits
/// words but never becomes an initial, so "(Base) Node" gives "BN" and
/// "- Relay" gives "RE". Characters are whole grapheme clusters, so accented
/// letters and emoji are never cut in half. A name with no letters or digits
/// but an emoji shows that emoji.
String? avatarInitials(String name) {
final words = <String>[];
final current = StringBuffer();
String? emoji;
for (final cluster in name.characters) {
if (_letterOrDigit.hasMatch(cluster)) {
current.write(cluster);
continue;
}
if (current.isNotEmpty) {
words.add(current.toString());
current.clear();
}
emoji ??= firstEmoji(cluster);
}
if (current.isNotEmpty) words.add(current.toString());
if (words.isEmpty) return emoji;
if (words.length == 1) {
return words.first.characters.take(2).toString().toUpperCase();
}
return (words[0].characters.first + words[1].characters.first).toUpperCase();
}
/// The most recent activity for [contact]: for chat nodes this includes the
/// last message, for other node types only the last advert or telemetry fix.
DateTime resolveContactLastSeen(Contact contact) {
+6 -19
View File
@@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
import '../l10n/l10n.dart';
import '../theme/mesh_theme.dart';
import '../theme/theme_icons.dart';
import 'contact_visuals.dart';
/// MeshCore shared design kit.
///
@@ -283,7 +284,8 @@ class StatTile extends StatelessWidget {
/// Initials avatar with a deterministic per-name hue, or a fixed [color]
/// for node-type coloring. Optional [icon] or themeable [iconSlot] replaces
/// initials.
/// initials. Initials come from [avatarInitials]; a name with no letters,
/// digits or emoji shows a generic person icon instead.
class AvatarCircle extends StatelessWidget {
final String name;
final double size;
@@ -320,7 +322,7 @@ class AvatarCircle extends StatelessWidget {
@override
Widget build(BuildContext context) {
final accent = color ?? _colorFor(name);
final initials = _initials(name);
final initials = avatarInitials(name);
final background = _tintedCardBackground(context, accent, 0.14);
// A theme picture (e.g. a holiday marker) fills the whole circle, the
// same as on the map, rather than sitting small inside the tint.
@@ -360,9 +362,9 @@ class AvatarCircle extends StatelessWidget {
size: size * 0.55,
color: readableAccent(accent, background, minContrast: 3),
)
: icon != null
: icon != null || initials == null
? Icon(
icon,
icon ?? Icons.person_outline,
size: size * 0.5,
color: readableAccent(accent, background, minContrast: 3),
)
@@ -376,21 +378,6 @@ class AvatarCircle extends StatelessWidget {
),
);
}
static String _initials(String name) {
final words = name
.trim()
.split(RegExp(r'\s+'))
.where((w) => w.isNotEmpty)
.toList();
if (words.isEmpty) return '?';
if (words.length == 1) {
return words.first.characters.take(2).toString().toUpperCase();
}
return (words.first.characters.take(1).toString() +
words[1].characters.take(1).toString())
.toUpperCase();
}
}
/// Four-bar signal strength indicator driven by an SNR value (dB), colored