deleteSet method
Deletes a NIP-51 set by name.
Broadcasts a deletion event for the set and removes it from the cache. Uses the logged-in account's signer.
name name of the set (d tag identifier)
kind kind of the set
specificRelays optional specific relays to broadcast the deletion to
Throws an exception if no event signer is available.
Implementation
Future deleteSet({
required String name,
required int kind,
Iterable<String>? specificRelays,
}) async {
if (_eventSigner == null) {
throw Exception(
"cannot broadcast private nip51 list without a signer that can sign");
}
/// remove all from cache
List<Nip01Event>? eventsInCache = await _cacheManager
.loadEvents(pubKeys: [_eventSigner!.getPublicKey()], kinds: [kind]);
eventsInCache = eventsInCache.where((event) {
if (event.getDtag() != null && event.getDtag() == name) {
return true;
}
return false;
}).toList();
Nip51Set? set = await getSetByName(name: name, kind: kind);
if (set != null) {
final broadcastResponse = _broadcast.broadcastDeletion(
eventId: set.id,
customSigner: _eventSigner,
);
await broadcastResponse.broadcastDoneFuture;
for (final event in eventsInCache) {
await _cacheManager.removeEvent(event.id);
}
}
}