import '../security/secret_store.dart'; /// User choices for the (Block 2) social layer: the coarse area to publish/ /// browse offers in, and which community relays to talk to. Backed by the OS /// keystore (via [SecretStore]) to honour "no plaintext at rest" — no /// shared_preferences. /// /// Both default to "unset": empty area and no relays mean the social layer is /// simply unavailable, and the app stays fully usable offline. class SocialSettings { SocialSettings(this._store); final SecretStore _store; static const _areaKey = 'tane.social.area_geohash'; static const _relaysKey = 'tane.social.relays'; /// The user's coarse area as a low-precision geohash (may be empty). Set /// manually or from device location; the transport coarsens it further. Future areaGeohash() async => (await _store.read(_areaKey)) ?? ''; Future setAreaGeohash(String geohash) => _store.write(_areaKey, geohash.trim().toLowerCase()); /// Configured community relay URLs (empty by default — the user adds their /// own; we bundle none, to avoid leaking metadata to third-party relays). Future> relayUrls() async { final raw = await _store.read(_relaysKey); if (raw == null || raw.isEmpty) return const []; return raw.split('\n').where((s) => s.trim().isNotEmpty).toList(); } Future setRelayUrls(List urls) => _store.write( _relaysKey, urls.map((u) => u.trim()).where((u) => u.isNotEmpty).join('\n'), ); /// Whether the social layer has enough config to attempt going online. Future get isConfigured async => (await relayUrls()).isNotEmpty && (await areaGeohash()).isNotEmpty; }