closeEventsSubscription method

  1. @override
void closeEventsSubscription(
  1. String subscriptionId, [
  2. String? relay
])
override

This method will close the subscription of the subscriptionId that you passed to it.

You can use after calling the startEventsSubscription method to close the subscription of the subscriptionId that you passed to it.

example:

Nostr.instance.relays.closeEventsSubscription("<subscriptionId>");

Implementation

@override
void closeEventsSubscription(String subscriptionId, [String? relay]) {
  final close = NostrRequestClose(
    subscriptionId: subscriptionId,
  );

  final serialized = close.serialized();

  if (relay != null) {
    final registeredRelay = nostrRegistry.getRelayWebSocket(relayUrl: relay);

    registeredRelay?.sink.add(serialized);

    utils.log(
      'Close request with subscription id: $subscriptionId is sent to relay with url: $relay',
    );

    return;
  }
  _runFunctionOverRelationIteration(
    (relay) {
      relay.socket.sink.add(serialized);
      utils.log(
        'Close request with subscription id: $subscriptionId is sent to relay with url: ${relay.url}',
      );
    },
  );
}