tane/apps/app_seeds/lib/services/profile_store.dart
vjrj 461bc3cb36 feat(profile): profile photo or seed-illustration avatar
Profiles had only a coloured-initial disc. Now each person can set an
avatar — a real photo OR one of our own seed illustrations (so
pseudonymity stays the default; no photo required).

- ui/avatar.dart: the one-string value scheme carried in the kind:0
  'picture' — a 'data:' photo thumbnail, a 'tane:seed:<glyph>' token, or
  empty. The Nostr ProfileTransport already published 'picture'.
- Photos ride inline as a tiny thumbnail (reuses offerThumbnailDataUri,
  24 KB cap) — no media server, like offer photos.
- avatar_edit.dart: pick/take a photo, choose a seed illustration, or
  remove; ProfileStore stores it; ProfileScreen shows a big editable
  avatar and publishes it.
- PeerAvatar renders photo / illustration / initial fallback.
- ProfileCache gains picture/setPicture; the inbox caches peers' avatars
  alongside their names.
- i18n avatar block (en/es/pt/ast). Tests: value scheme + PeerAvatar
  render modes, store + cache round-trips.

Follow-up: render peers' avatars in chat/market/your-people (thread the
cached picture into PeerAvatar at each call site).
2026-07-11 22:21:52 +02:00

44 lines
1.7 KiB
Dart

import '../security/secret_store.dart';
/// Your own display name and short "about", persisted locally (keystore-backed,
/// no plaintext at rest). The network copy is a published NIP-01 kind:0 event;
/// this local copy prefills the editor and works offline.
class ProfileStore {
/// [accountScope] namespaces the keys per social identity (empty = the
/// original identity's legacy keys). See [socialAccountScope].
ProfileStore(this._store, {String accountScope = ''})
: _base = accountScope.isEmpty
? 'tane.social.profile.'
: 'tane.social.$accountScope.profile.';
final SecretStore _store;
final String _base;
String get _nameKey => '${_base}name';
String get _aboutKey => '${_base}about';
String get _g1Key => '${_base}g1';
String get _avatarKey => '${_base}avatar';
Future<String> name() async => (await _store.read(_nameKey)) ?? '';
Future<String> about() async => (await _store.read(_aboutKey)) ?? '';
/// Your Ğ1 (Duniter) address, if you chose to share one.
Future<String> g1() async => (await _store.read(_g1Key)) ?? '';
/// Your avatar: either a `data:image/jpeg;base64,…` photo thumbnail or a
/// `tane:seed:<glyph>` illustration token (see `ui/avatar.dart`). Empty for
/// the default coloured-initial disc. Published as the kind:0 `picture`.
Future<String> avatar() async => (await _store.read(_avatarKey)) ?? '';
Future<void> save({
required String name,
required String about,
String g1 = '',
String avatar = '',
}) async {
await _store.write(_nameKey, name.trim());
await _store.write(_aboutKey, about.trim());
await _store.write(_g1Key, g1.trim());
await _store.write(_avatarKey, avatar.trim());
}
}