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).
This commit is contained in:
parent
74c7edaecd
commit
ec56819fbf
19 changed files with 375 additions and 12 deletions
|
|
@ -117,12 +117,20 @@ class InboxService {
|
|||
final cache = _profileCache;
|
||||
final session = _session;
|
||||
if (cache == null || session == null) return;
|
||||
if (await cache.name(peerPubkey) != null) return; // already known
|
||||
// Fetch once we're missing either the name or the avatar for this peer.
|
||||
final haveName = await cache.name(peerPubkey) != null;
|
||||
final havePic = await cache.picture(peerPubkey) != null;
|
||||
if (haveName && havePic) return;
|
||||
try {
|
||||
final profile = await session.profile.fetch(peerPubkey);
|
||||
if (profile != null && profile.name.isNotEmpty) {
|
||||
await cache.setName(peerPubkey, profile.name);
|
||||
if (!_changes.isClosed) _changes.add(null); // re-render with the name
|
||||
if (profile == null) return;
|
||||
if (profile.name.isNotEmpty) await cache.setName(peerPubkey, profile.name);
|
||||
if (profile.picture.isNotEmpty) {
|
||||
await cache.setPicture(peerPubkey, profile.picture);
|
||||
}
|
||||
if ((profile.name.isNotEmpty || profile.picture.isNotEmpty) &&
|
||||
!_changes.isClosed) {
|
||||
_changes.add(null); // re-render with the name/avatar
|
||||
}
|
||||
} catch (_) {
|
||||
// best effort — the short key shows meanwhile
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ class ProfileCache {
|
|||
final SecretStore _store;
|
||||
final String _prefix;
|
||||
|
||||
// Avatars peers have published (kind:0 `picture`) live under a parallel key
|
||||
// namespace, so a name and an avatar are cached independently.
|
||||
String get _picPrefix => '${_prefix.substring(0, _prefix.length - 5)}picture.';
|
||||
|
||||
/// The cached name for [pubkeyHex], or null if none is known.
|
||||
Future<String?> name(String pubkeyHex) async {
|
||||
final value = await _store.read('$_prefix$pubkeyHex');
|
||||
|
|
@ -22,6 +26,16 @@ class ProfileCache {
|
|||
|
||||
Future<void> setName(String pubkeyHex, String name) =>
|
||||
_store.write('$_prefix$pubkeyHex', name.trim());
|
||||
|
||||
/// The cached avatar for [pubkeyHex] (a `data:` photo or `tane:seed:<glyph>`
|
||||
/// token), or null if none is known.
|
||||
Future<String?> picture(String pubkeyHex) async {
|
||||
final value = await _store.read('$_picPrefix$pubkeyHex');
|
||||
return (value == null || value.isEmpty) ? null : value;
|
||||
}
|
||||
|
||||
Future<void> setPicture(String pubkeyHex, String picture) =>
|
||||
_store.write('$_picPrefix$pubkeyHex', picture.trim());
|
||||
}
|
||||
|
||||
/// A compact, human-ish rendering of a public key when no name is known yet.
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class ProfileStore {
|
|||
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)) ?? '';
|
||||
|
|
@ -24,13 +25,20 @@ class ProfileStore {
|
|||
/// 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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue