handleRequest method
Implementation
@override
Future<void> handleRequest(RequestState state) async {
await _relayManager.seedRelaysConnected;
state.request.onTimeout = (state) {
Logger.log.w(
"request ${state.request.id} : ${state.request.filters} timed out after ${state.request.timeout}");
for (var url in state.requests.keys) {
_relayManager.sendCloseToRelay(url, state.id);
}
_relayManager.removeInFlightRequestById(state.id);
};
if (state.request.relaySet != null) {
return await doNostrRequestWithRelaySet(state);
}
if (state.request.explicitRelays != null &&
state.request.explicitRelays!.isNotEmpty) {
for (var url in state.request.explicitRelays!) {
await _relayManager.reconnectRelay(url);
state.addRequest(
url, RelaySet.sliceFilterAuthors(state.request.filters.first));
}
} else {
for (var url in _relayManager.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);
}
}