broadcastAddNip51ListRelay method

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

Implementation

Future<Nip51List> broadcastAddNip51ListRelay(
  int kind,
  String relayUrl,
  Iterable<String>? broadcastRelays, {
  bool private = false,
}) 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);
  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);

  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;
}