From fea9005732607ee58a4bcb113b1805028954498a Mon Sep 17 00:00:00 2001 From: Michael Jurkoic Date: Sun, 17 Mar 2024 18:32:45 -0500 Subject: Add service methods to close filter subscriptions --- include/nostr.hpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'include/nostr.hpp') diff --git a/include/nostr.hpp b/include/nostr.hpp index 22d9956..c410046 100644 --- a/include/nostr.hpp +++ b/include/nostr.hpp @@ -151,13 +151,28 @@ public: std::tuple queryRelays(Filters filters); // TODO: Write a method that receives events for an active subscription. - // TODO: Write a method that closes active subscriptions. + + /** + * @brief Closes the subscription with the given ID on all open relay connections. + * @returns A tuple of `RelayList` objects, of the form ``, indicating + * to which relays the message was sent successfully, and which relays failed to receive the + * message. + */ + std::tuple closeSubscription(std::string subscriptionId); + + /** + * @brief Closes all open subscriptions on the given relays. + * @returns A tuple of `RelayList` objects, of the form ``, indicating + * to which relays the message was sent successfully, and which relays failed to receive the + * message. + */ + std::tuple closeSubscriptions(RelayList relays); private: std::mutex _propertyMutex; RelayList _defaultRelays; RelayList _activeRelays; - std::unordered_map> _subscriptionIds; + std::unordered_map> _subscriptions; client::IWebSocketClient* _client; /** @@ -198,5 +213,18 @@ private: * @returns A stringified UUID. */ std::string generateSubscriptionId(); + + /** + * @brief Generates a message requesting a relay to close the subscription with the given ID. + * @returns A stringified JSON object representing the close request. + */ + std::string generateCloseRequest(std::string subscriptionId); + + /** + * @brief Indicates whether the connection to the given relay has a subscription with the given + * ID. + * @returns True if the relay has the subscription, false otherwise. + */ + bool hasSubscription(std::string relay, std::string subscriptionId); }; } // namespace nostr -- cgit