closeSubscription method
Closes a Nostr network subscription
Implementation
Future<void> closeSubscription(String subId) async {
final relayUrls = _globalState.inFlightRequests[subId]?.requests.keys;
if (relayUrls == null) {
Logger.log.w("no relay urls found for subscription $subId, cannot close");
return;
}
Iterable<RelayConnectivity> relays = _relayManager.connectedRelays
.whereType<RelayConnectivity>()
.where((relay) => relayUrls.contains(relay.url));
for (final relay in relays) {
_relayManager.sendCloseToRelay(relay.url, subId);
}
final state = _globalState.inFlightRequests[subId];
if (state == null) {
Logger.log
.w("no request state found for subscription $subId, cannot close");
return;
}
state.close();
}