broadcastAddNip51ListRelay method

Future<Nip51List> broadcastAddNip51ListRelay(
  1. int kind,
  2. String relayUrl,
  3. Iterable<String> broadcastRelays,
  4. EventSigner eventSigner, {
  5. bool private = false,
})

Implementation

Future<Nip51List> broadcastAddNip51ListRelay(int kind, String relayUrl,
    Iterable<String> broadcastRelays, EventSigner eventSigner,
    {bool private = false}) async {
  if (private && !eventSigner.canSign()) {
    throw Exception(
        "cannot broadcast private nip51 list without a signer that can sign");
  }
  Nip51List? list =
      await getSingleNip51List(kind, eventSigner, forceRefresh: true);
  list ??= Nip51List(
      kind: kind,
      pubKey: eventSigner.getPublicKey(),
      createdAt: Helpers.now,
      elements: []);
  list.addRelay(relayUrl, private);
  list.createdAt = Helpers.now;
  Nip01Event event = await list.toEvent(eventSigner);
  // print(event);
  await Future.wait([
    _relayManager.broadcastEvent(event, broadcastRelays, eventSigner),
  ]);
  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;
}