handleRequest method

  1. @override
Future<void> handleRequest(
  1. RequestState state
)
override

Implementation

@override
Future<void> handleRequest(RequestState state) async {
  await _relayManager.seedRelaysConnected;

  if (state.request.relaySet != null) {
    return await doNostrRequestWithRelaySet(state);
  }
  if (state.request.explicitRelays != null &&
      state.request.explicitRelays!.isNotEmpty) {
    for (final url in state.request.explicitRelays!) {
      await _relayManager.connectRelay(
          dirtyUrl: url, connectionSource: ConnectionSource.explicit);
      state.addRequest(
          url, RelaySet.sliceFilterAuthors(state.request.filters.first));
    }
  } else {
    for (final url in _bootstrapRelays) {
      state.addRequest(
          url, RelaySet.sliceFilterAuthors(state.request.filters.first));
    }
  }
  _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);
  }
}