handleRequest method

  1. @override
void handleRequest(
  1. RequestState requestState
)
override

If you request anything from the nostr network put it here and the relay jit manager will try to find the right relay and use it if no relay is found the request will be blasted to all connected relays (on start seed Relays)

Implementation

@override
void handleRequest(
  RequestState requestState,
) async {
  await seedRelaysConnected;

  final ndkRequest = requestState.request;

  //clean ignore relays
  List<String> cleanIgnoreRelays = cleanRelayUrls(ignoreRelays);

  /// ["REQ", <subscription_id>, <filters1>, <filters2>, ...]
  /// user can provide multiple filters
  for (var filter in requestState.unresolvedFilters) {
    // filter different types of filters/requests because each requires a different strategy

    if ((filter.authors != null && filter.authors!.isNotEmpty)) {
      RelayJitPubkeyStrategy.handleRequest(
        requestState: requestState,
        cacheManager: cache,
        filter: filter,
        connectedRelays: globalState.connectedRelays,
        desiredCoverage: ndkRequest.desiredCoverage,
        closeOnEOSE: ndkRequest.closeOnEOSE,
        direction: ReadWriteMarker
            .writeOnly, // the author should write on the persons write relays
        ignoreRelays: cleanIgnoreRelays,
        onMessage: onMessage,
      );
      continue;
    }

    if (filter.pTags?.isNotEmpty != null && filter.pTags!.isNotEmpty) {
      RelayJitPubkeyStrategy.handleRequest(
        requestState: requestState,
        cacheManager: cache,
        filter: filter,
        connectedRelays: globalState.connectedRelays,
        desiredCoverage: ndkRequest.desiredCoverage,
        closeOnEOSE: ndkRequest.closeOnEOSE,
        direction: ReadWriteMarker
            .readOnly, // others should mention on the persons read relays
        ignoreRelays: cleanIgnoreRelays,
        onMessage: onMessage,
      );
      continue;
    }

    if (filter.search != null) {
      throw UnimplementedError("search filter not implemented yet");
    }

    if (filter.ids != null) {
      throw UnimplementedError("ids filter not implemented yet");
    }

    /// unknown filter strategy, blast to all connected relays
    RelayJitBlastAllStrategy.handleRequest(
      requestState: requestState,
      filter: filter,
      connectedRelays: globalState.connectedRelays,
      closeOnEOSE: requestState.request.closeOnEOSE,
    );
  }
}