handleEventBroadcast method

  1. @override
NdkBroadcastResponse handleEventBroadcast({
  1. required Nip01Event nostrEvent,
  2. required EventSigner? signer,
  3. required Stream<List<RelayBroadcastResponse>> doneStream,
  4. 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? signer,
  required Stream<List<RelayBroadcastResponse>> doneStream,
  Iterable<String>? specificRelays,
}) {
  Future<void> asyncStuff() async {
    await relayManagerLight.seedRelaysConnected;

    if (signer != null) {
      await signer.sign(nostrEvent);
    }

    if (specificRelays != null) {
      return RelayJitBroadcastSpecificRelaysStrategy.broadcast(
        specificRelays: specificRelays.toList(),
        relayManager: relayManagerLight,
        eventToPublish: nostrEvent,
        connectedRelays: relayManagerLight.connectedRelays
            .whereType<RelayConnectivity<JitEngineRelayConnectivityData>>()
            .toList(),
      );
    }

    // default publish to own outbox
    await RelayJitBroadcastOutboxStrategy.broadcast(
      eventToPublish: nostrEvent,
      connectedRelays: relayManagerLight.connectedRelays
          .whereType<RelayConnectivity<JitEngineRelayConnectivityData>>()
          .toList(),
      cacheManager: cache,
      relayManager: relayManagerLight,
    );

    // check if we need to publish to others inboxes
    if (nostrEvent.pTags.isNotEmpty) {
      await RelayJitBroadcastOtherReadStrategy.broadcast(
        eventToPublish: nostrEvent,
        connectedRelays: relayManagerLight.connectedRelays
            .whereType<RelayConnectivity<JitEngineRelayConnectivityData>>()
            .toList(),
        cacheManager: cache,
        relayManager: relayManagerLight,
        pubkeysOfInbox: nostrEvent.pTags,
      );
    }
  }

  asyncStuff();
  return NdkBroadcastResponse(
    publishEvent: nostrEvent,
    broadcastDoneStream: doneStream,
  );
}