diff options
author | Michael Jurkoic <mjjurkoic@gmail.com> | 2024-03-19 09:12:00 -0500 |
---|---|---|
committer | Michael Jurkoic <mjjurkoic@gmail.com> | 2024-03-19 09:12:00 -0500 |
commit | 8dbce9cd5aab9129e66a0c04e31467d172344f19 (patch) | |
tree | a5f76cebf5af6928ca4c6778920a8b09b7e96bec /include | |
parent | 6dde23e6c66e846c64d49c5258f0dbf44e3d0374 (diff) |
Move relay payload parsing into NostrService
Preserve separation of concerns.
Diffstat (limited to 'include')
-rw-r--r-- | include/client/web_socket_client.hpp | 6 | ||||
-rw-r--r-- | include/nostr.hpp | 7 |
2 files changed, 9 insertions, 4 deletions
diff --git a/include/client/web_socket_client.hpp b/include/client/web_socket_client.hpp index f676e59..3ef2b86 100644 --- a/include/client/web_socket_client.hpp +++ b/include/client/web_socket_client.hpp @@ -45,10 +45,10 @@ public: /** * @brief Sets up a message handler for the given server. * @param uri The URI of the server to which the message handler should be attached. - * @param messageHandler A callable object that will be invoked with the subscription ID and - * the message contents when the client receives a message from the server. + * @param messageHandler A callable object that will be invoked with the payload the client + * receives from the server. */ - virtual void receive(std::string uri, std::function<void(const std::string&, const std::string&)> messageHandler) = 0; + virtual void receive(std::string uri, std::function<void(const std::string&)> messageHandler) = 0; /** * @brief Closes the connection to the given server. diff --git a/include/nostr.hpp b/include/nostr.hpp index 3e60d7b..2b04862 100644 --- a/include/nostr.hpp +++ b/include/nostr.hpp @@ -170,7 +170,7 @@ 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<void(std::string, Event)> responseHandler); + std::string queryRelays(Filters filters, std::function<void(const std::string&, Event)> responseHandler); /** * @brief Get any new events received since the last call to this method, across all @@ -285,6 +285,11 @@ private: bool hasSubscription(std::string relay, std::string subscriptionId); /** + * @brief Parses messages received from the relay and invokes the appropriate message handler. + */ + void onMessage(std::string message, std::function<void(const std::string&, Event)> eventHandler); + + /** * @brief A default message handler for events returned from relay queries. * @param subscriptionId The ID of the subscription for which the event was received. * @param event The event received from the relay. |