feat(social): local blocklist — hide blocked authors' offers, chats and incoming messages, with unblock management

This commit is contained in:
vjrj 2026-07-13 01:03:10 +02:00
parent 5d25f65f76
commit 11b242edbf
13 changed files with 399 additions and 4 deletions

View file

@ -17,6 +17,7 @@ class SocialSettings {
static const _areaKey = 'tane.social.area_geohash';
static const _relaysKey = 'tane.social.relays';
static const _searchPrecisionKey = 'tane.social.search_precision';
static const _blockedKey = 'tane.social.blocked_pubkeys';
/// How wide "your zone" searches, as a geohash prefix length: 5 ±2.4 km
/// ("very close"), 4 ±20 km ("around here"), 3 ±78 km ("my region").
@ -80,4 +81,32 @@ class SocialSettings {
/// Whether the social layer has enough config to attempt going online.
Future<bool> get isConfigured async =>
(await relayUrls()).isNotEmpty && (await areaGeohash()).isNotEmpty;
/// Pubkeys (hex) this user has blocked: their offers are hidden, their
/// chats disappear and their incoming messages are dropped. Purely local
/// nothing is published about who you block.
Future<Set<String>> blockedPubkeys() async {
final raw = await _store.read(_blockedKey);
if (raw == null) return <String>{};
return raw
.split('\n')
.map((s) => s.trim().toLowerCase())
.where((s) => s.isNotEmpty)
.toSet();
}
Future<bool> isBlocked(String pubkeyHex) async =>
(await blockedPubkeys()).contains(pubkeyHex.trim().toLowerCase());
Future<void> block(String pubkeyHex) async {
final set = await blockedPubkeys()
..add(pubkeyHex.trim().toLowerCase());
await _store.write(_blockedKey, set.join('\n'));
}
Future<void> unblock(String pubkeyHex) async {
final set = await blockedPubkeys()
..remove(pubkeyHex.trim().toLowerCase());
await _store.write(_blockedKey, set.join('\n'));
}
}