broadcastRemoveNip51Relay method
Implementation
Future<Nip51List?> broadcastRemoveNip51Relay(
int kind,
String relayUrl,
Iterable<String>? broadcastRelays, {
List<String>? defaultRelaysIfEmpty,
}) async {
if (_eventSigner == null) {
throw Exception(
"cannot broadcast private nip51 list without a signer that can sign");
}
Nip51List? list = await getSingleNip51List(
kind,
_eventSigner,
forceRefresh: true,
);
if ((list == null || list.allRelays.isEmpty) &&
defaultRelaysIfEmpty != null &&
defaultRelaysIfEmpty.isNotEmpty) {
list = Nip51List(
kind: kind,
pubKey: _eventSigner.getPublicKey(),
createdAt: Helpers.now,
elements: []);
list.privateRelays = defaultRelaysIfEmpty;
}
if (list != null && list.allRelays.isNotEmpty) {
list.removeRelay(relayUrl);
list.createdAt = Helpers.now;
Nip01Event event = await list.toEvent(_eventSigner);
final broadcastResponse = _broadcast.broadcast(
nostrEvent: event,
specificRelays: broadcastRelays,
customSigner: _eventSigner,
);
await broadcastResponse.broadcastDoneFuture;
List<Nip01Event>? events = await _cacheManager
.loadEvents(pubKeys: [_eventSigner.getPublicKey()], kinds: [kind]);
for (var event in events) {
_cacheManager.removeEvent(event.id);
}
await _cacheManager.saveEvent(event);
}
return list;
}