tane/apps/app_seeds/lib/ui/avatar.dart
vjrj 1c2b3d5e8d feat(profile): generated default avatars (boring-avatars beam) from pubkey
People without a photo or seed illustration now get a deterministic
pattern avatar drawn from their pubkey (flutter_boring_avatars, MIT),
in an earthy seed-tone palette, replacing the coloured-initial disc.
Same pubkey renders the same picture on every device with nothing shared.
2026-07-12 21:59:10 +02:00

40 lines
1.5 KiB
Dart

import 'seed_glyph.dart';
/// A profile avatar is carried in one string (stored locally and published as
/// the NIP-01 kind:0 `picture`), in one of three shapes:
/// - `data:image/jpeg;base64,…` — a tiny photo thumbnail (rides inline, no
/// media server, like offer photos);
/// - `tane:seed:<name>` — one of our own seed illustrations (for people who'd
/// rather not put a real photo — pseudonymity stays the default);
/// - empty — a pattern avatar generated deterministically from the pubkey.
const avatarGlyphPrefix = 'tane:seed:';
/// The seed illustrations offered as ready-made avatars. Names are the stable
/// storage key (appended to [avatarGlyphPrefix]); the glyphs already ship in
/// [SeedGlyphs]. Order is the picker order.
const avatarGlyphNames = <String>[
'jars',
'sack',
'jar',
'scattered',
'pouring',
'mug',
'bigSpoon',
'smallSpoon',
];
/// The glyph char for an avatar illustration [name], or null if unknown.
String? avatarGlyphChar(String name) => switch (name) {
'jars' => SeedGlyphs.jars,
'sack' => SeedGlyphs.sack,
'jar' => SeedGlyphs.jar,
'scattered' => SeedGlyphs.scattered,
'pouring' => SeedGlyphs.pouring,
'mug' => SeedGlyphs.mug,
'bigSpoon' => SeedGlyphs.bigSpoon,
'smallSpoon' => SeedGlyphs.smallSpoon,
_ => null,
};
/// The token that selects illustration [name] (e.g. `tane:seed:jars`).
String avatarGlyphToken(String name) => '$avatarGlyphPrefix$name';