From 14ba707c600f13012b3b7f441541f9a6db8ddb8a Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Tue, 7 May 2024 09:07:25 -0500 Subject: Update and test methods for closing subscriptions --- include/nostr.hpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'include/nostr.hpp') diff --git a/include/nostr.hpp b/include/nostr.hpp index 326a637..e76d1e5 100644 --- a/include/nostr.hpp +++ b/include/nostr.hpp @@ -217,21 +217,25 @@ public: */ std::tuple closeSubscription(std::string subscriptionId); + /** + * @brief Closes the subscription with the given ID on the given relay. + * @returns True if the relay received the CLOSE message, false otherwise. + * @remark If the subscription does not exist on the given relay, or if the relay is not + * connected, the method will do nothing and return false. + */ + bool closeSubscription(std::string subscriptionId, std::string relay); + /** * @brief Closes all open subscriptions 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. + * @returns A list of any subscription IDs that failed to close. */ - std::tuple closeSubscriptions(); + std::vector closeSubscriptions(); /** * @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. + * @returns A list of any subscription IDs that failed to close. */ - std::tuple closeSubscriptions(RelayList relays); + std::vector closeSubscriptions(RelayList relays); private: ///< The maximum number of events the service will store for each subscription. @@ -248,7 +252,7 @@ private: RelayList _defaultRelays; ///< The set of Nostr relays to which the service is currently connected. RelayList _activeRelays; - ///< A map from relay URIs to the subscription IDs open on each relay. + ///< A map from subscription IDs to the relays on which each subscription is open. std::unordered_map> _subscriptions; /** @@ -297,11 +301,17 @@ private: 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. + * @brief Indicates whether the the service has an open subscription with the given ID. + * @returns True if the service has the subscription, false otherwise. + */ + bool hasSubscription(std::string subscriptionId); + + /** + * @brief Indicates whether the service has an open subscription with the given ID on the given + * relay. + * @returns True if the subscription exists on the relay, false otherwise. */ - bool hasSubscription(std::string relay, std::string subscriptionId); + bool hasSubscription(std::string subscriptionId, std::string relay); /** * @brief Parses EVENT messages received from the relay and invokes the given event handler. -- cgit