From ecc502a5c15a29a9928c8ec462883774bfc9f35a Mon Sep 17 00:00:00 2001 From: Michael Jurkoic Date: Mon, 25 Mar 2024 08:07:38 -0500 Subject: Use shared pointers for filters and events --- include/nostr.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'include/nostr.hpp') diff --git a/include/nostr.hpp b/include/nostr.hpp index 1e462e7..5f5ce25 100644 --- a/include/nostr.hpp +++ b/include/nostr.hpp @@ -167,7 +167,7 @@ public: * @remarks The service will store a limited number of events returned from the relay for the * given filters. These events may be retrieved via `getNewEvents`. */ - std::string queryRelays(Filters filters); + std::string queryRelays(std::shared_ptr filters); /** * @brief Queries all open relay connections for events matching the given set of filters. @@ -179,21 +179,23 @@ public: * events returned from the relay for the given filters. The service will not store the * events, and they will not be accessible via `getNewEvents`. */ - std::string queryRelays(Filters filters, std::function responseHandler); + std::string queryRelays( + std::shared_ptr filters, + std::function)> responseHandler); /** * @brief Get any new events received since the last call to this method, across all * subscriptions. * @returns A pointer to a vector of new events. */ - std::vector getNewEvents(); + std::vector> getNewEvents(); /** * @brief Get any new events received since the last call to this method, for the given * subscription. * @returns A pointer to a vector of new events. */ - std::vector getNewEvents(std::string subscriptionId); + std::vector> getNewEvents(std::string subscriptionId); /** * @brief Closes the subscription with the given ID on all open relay connections. @@ -237,7 +239,7 @@ private: ///< A map from relay URIs to the subscription IDs open on each relay. std::unordered_map> _subscriptions; ///< A map from subscription IDs to the events returned by the relays for each subscription. - std::unordered_map> _events; + std::unordered_map>> _events; ///< A map from the subscription IDs to the ID of the latest read event for each subscription. std::unordered_map _lastRead; @@ -296,7 +298,9 @@ private: /** * @brief Parses messages received from the relay and invokes the appropriate message handler. */ - void onMessage(std::string message, std::function eventHandler); + void onMessage( + std::string message, + std::function)> eventHandler); /** * @brief A default message handler for events returned from relay queries. @@ -305,7 +309,7 @@ private: * @remark By default, new events are stored in a map of subscription IDs to vectors of events. * Events are retrieved by calling `getNewEvents` or `getNewEvents(subscriptionId)`. */ - void onEvent(std::string subscriptionId, Event event); + void onEvent(std::string subscriptionId, std::shared_ptr event); }; class ISigner -- cgit