requestRelays method

Future<NdkResponse> requestRelays(
  1. String name,
  2. Iterable<String> urls,
  3. Filter filter, {
  4. Duration timeout = kDefaultStreamIdleTimeout,
  5. bool closeOnEOSE = true,
})

Implementation

Future<NdkResponse> requestRelays(
  String name,
  Iterable<String> urls,
  Filter filter, {
  Duration timeout = kDefaultStreamIdleTimeout,
  bool closeOnEOSE = true,
}) async {
  String id = Helpers.getRandomString(10);
  RequestState state = RequestState(closeOnEOSE
      ? NdkRequest.query(
          id,
          name: name,
          filters: [filter],
          timeoutDuration: timeout,
        )
      : NdkRequest.subscription(
          id,
          name: name,
          filters: [],
        ));

  for (var url in urls) {
    state.addRequest(url, RelaySet.sliceFilterAuthors(filter));
  }
  _globalState.inFlightRequests[state.id] = state;

  List<String> notSent = [];
  for (MapEntry<String, RelayRequestState> entry in state.requests.entries) {
    if (!doRelayRequest(state.id, entry.value)) {
      notSent.add(entry.key);
    }
  }
  for (var url in notSent) {
    state.requests.remove(url);
  }

  return NdkResponse(state.id, state.stream);
}