diff options
-rw-r--r-- | include/service/nostr_service_base.hpp | 4 | ||||
-rw-r--r-- | src/service/nostr_service_base.cpp | 11 |
2 files changed, 8 insertions, 7 deletions
diff --git a/include/service/nostr_service_base.hpp b/include/service/nostr_service_base.hpp index f1b91d1..950cf8d 100644 --- a/include/service/nostr_service_base.hpp +++ b/include/service/nostr_service_base.hpp @@ -1,6 +1,7 @@ #pragma once #include <functional> +#include <future> #include <memory> #include <mutex> #include <string> @@ -146,9 +147,8 @@ public: std::tuple<std::vector<std::string>, std::vector<std::string>> publishEvent( std::shared_ptr<data::Event> event) override; - // TODO: Make this method return a promise. // TODO: Add a timeout to this method to prevent hanging while waiting for the relay. - std::vector<std::shared_ptr<data::Event>> queryRelays( + std::future<std::vector<std::shared_ptr<data::Event>>> queryRelays( std::shared_ptr<data::Filters> filters) override; std::string queryRelays( diff --git a/src/service/nostr_service_base.cpp b/src/service/nostr_service_base.cpp index 26748e0..a384492 100644 --- a/src/service/nostr_service_base.cpp +++ b/src/service/nostr_service_base.cpp @@ -2,6 +2,7 @@ #include <future> #include <stdexcept> #include <thread> +#include <unordered_set> #include <uuid_v4.h> @@ -191,7 +192,7 @@ tuple<vector<string>, vector<string>> NostrServiceBase::publishEvent( future<vector<shared_ptr<nostr::data::Event>>> NostrServiceBase::queryRelays( shared_ptr<nostr::data::Filters> filters) { - return async(launch::async, [this, filters]() -> vector<shared_ptr<Event>> + return async(launch::async, [this, filters]() -> vector<shared_ptr<nostr::data::Event>> { if (filters->limit > 64 || filters->limit < 1) { @@ -199,9 +200,9 @@ future<vector<shared_ptr<nostr::data::Event>>> NostrServiceBase::queryRelays( filters->limit = 16; } - vector<shared_ptr<Event>> events; + vector<shared_ptr<nostr::data::Event>> events; - string subscriptionId = this->generateSubscriptionId(); + string subscriptionId = this->_generateSubscriptionId(); string request; try @@ -237,9 +238,9 @@ future<vector<shared_ptr<nostr::data::Event>>> NostrServiceBase::queryRelays( relay, [this, &relay, &events, &eosePromise, &uniqueEventIds](string payload) { - this->onSubscriptionMessage( + this->_onSubscriptionMessage( payload, - [&events, &uniqueEventIds](const string&, shared_ptr<Event> event) + [&events, &uniqueEventIds](const string&, shared_ptr<nostr::data::Event> event) { // Check if the event is unique before adding. if (uniqueEventIds.insert(event->id).second) |