broadcastRemoveNip51SetRelay method
Implementation
Future<Nip51Set?> broadcastRemoveNip51SetRelay(String relayUrl, String name,
Iterable<String> broadcastRelays, EventSigner eventSigner,
{List<String>? defaultRelaysIfEmpty, bool private = false}) async {
if (private && !eventSigner.canSign()) {
throw Exception(
"cannot broadcast private nip51 list without a signer that can sign");
}
Nip51Set? relaySet = await getSingleNip51RelaySet(
name,
eventSigner,
forceRefresh: true,
);
if ((relaySet == null || relaySet.allRelays.isEmpty) &&
defaultRelaysIfEmpty != null &&
defaultRelaysIfEmpty.isNotEmpty) {
relaySet = Nip51Set(
name: name,
pubKey: eventSigner.getPublicKey(),
createdAt: Helpers.now,
elements: []);
relaySet.privateRelays = defaultRelaysIfEmpty;
}
if (relaySet != null) {
relaySet.removeRelay(relayUrl);
relaySet.createdAt = Helpers.now;
Nip01Event event = await relaySet.toEvent(eventSigner);
await Future.wait([
_relayManager.broadcastEvent(event, broadcastRelays, eventSigner),
]);
List<Nip01Event>? events = await _cacheManager.loadEvents(
pubKeys: [eventSigner.getPublicKey()], kinds: [Nip51List.RELAY_SET]);
events = events.where((event) {
if (event.getDtag() != null && event.getDtag() == name) {
return true;
}
return false;
}).toList();
for (var event in events) {
_cacheManager.removeEvent(event.id);
}
await _cacheManager.saveEvent(event);
}
return relaySet;
}