handleEventBroadcast method

  1. @override
NdkBroadcastResponse handleEventBroadcast({
  1. required Nip01Event nostrEvent,
  2. required EventSigner mySigner,
  3. Iterable<String>? specificRelays,
})
override

broadcasts given event using inbox/outbox (gossip) if explicit relays are given they are used instead nostrEvent event to publish explicitRelays used instead of gossip if set

Implementation

@override
NdkBroadcastResponse handleEventBroadcast({
  required Nip01Event nostrEvent,
  required EventSigner mySigner,
  Iterable<String>? specificRelays,
}) {
  Future<void> asyncStuff() async {
    await seedRelaysConnected;

    if (specificRelays != null) {
      return RelayJitBroadcastAllStrategy.broadcast(
        eventToPublish: nostrEvent,
        connectedRelays: globalState.connectedRelays,
        signer: mySigner,
      );
    }

    // default publish to own outbox
    await RelayJitBroadcastOutboxStrategy.broadcast(
      eventToPublish: nostrEvent,
      connectedRelays: globalState.connectedRelays,
      cacheManager: cache,
      onMessage: onMessage,
      signer: mySigner,
    );

    // check if we need to publish to others inboxes
    if (nostrEvent.pTags.isNotEmpty) {
      await RelayJitBroadcastOtherReadStrategy.broadcast(
        eventToPublish: nostrEvent,
        connectedRelays: globalState.connectedRelays,
        cacheManager: cache,
        onMessage: onMessage,
        signer: mySigner,
        pubkeysOfInbox: nostrEvent.pTags,
      );
    }
  }

  asyncStuff();
  return NdkBroadcastResponse(publishedEvent: nostrEvent);
}