tane/apps/app_seeds/lib/services/profile_cache.dart
vjrj 9cc1a5e171 feat(block2): show contact names (resolve peers' published profiles)
Closes the profile loop — peers now appear by name, not a raw key.
- ProfileCache: keystore-backed cache of peers' published display names (works
  offline) + shortPubkey() fallback.
- Chat: the app bar shows the peer's name (cached first, then freshened from
  their kind:0 over the session); falls back to a short key.
- Inbox: each conversation shows the cached name, and missing names are resolved
  over one session and cached.
- Wired via DI + TaneApp(profileCache).

Analyzer clean; ProfileCache covered by a plain test.
2026-07-10 12:47:48 +02:00

25 lines
972 B
Dart

import '../security/secret_store.dart';
/// Remembers the display names peers have published (their NIP-01 kind:0
/// `name`), so the inbox and chat show a human name instead of a raw key —
/// even offline. Keystore-backed (no plaintext at rest).
class ProfileCache {
ProfileCache(this._store);
final SecretStore _store;
static const _prefix = 'tane.social.name.';
/// The cached name for [pubkeyHex], or null if none is known.
Future<String?> name(String pubkeyHex) async {
final value = await _store.read('$_prefix$pubkeyHex');
return (value == null || value.isEmpty) ? null : value;
}
Future<void> setName(String pubkeyHex, String name) =>
_store.write('$_prefix$pubkeyHex', name.trim());
}
/// A compact, human-ish rendering of a public key when no name is known yet.
String shortPubkey(String pubkeyHex) => pubkeyHex.length <= 12
? pubkeyHex
: '${pubkeyHex.substring(0, 6)}${pubkeyHex.substring(pubkeyHex.length - 4)}';