diff --git a/bin/nodejs/callback.h b/bin/nodejs/callback.h index fd97e1c971cd278fe2b4d0ff703f21c6c3538ac0..f1e3072e3b9b40bdb627a05f8196379da718f28e 100644 --- a/bin/nodejs/callback.h +++ b/bin/nodejs/callback.h @@ -54,6 +54,7 @@ Persistent<Function> conversationPreferencesUpdatedCb; Persistent<Function> messageSendCb; Persistent<Function> accountProfileReceivedCb; Persistent<Function> profileReceivedCb; +Persistent<Function> userSearchEndedCb; std::queue<std::function<void()>> pendingSignals; std::mutex pendingSignalsLock; @@ -153,6 +154,8 @@ getPresistentCb(std::string_view signal) return &accountProfileReceivedCb; else if (signal == "ProfileReceived") return &profileReceivedCb; + else if (signal == "UserSearchEnded") + return &userSearchEndedCb; else return nullptr; } @@ -556,6 +559,24 @@ knownDevicesChanged(const std::string& accountId, const std::map<std::string, st uv_async_send(&signalAsync); } +void +userSearchEnded(const std::string& accountId,int state, const std::string& query, const std::vector<std::map<std::string, std::string>>& results) +{ + std::lock_guard lock(pendingSignalsLock); + pendingSignals.emplace([accountId,state,query, results]() { + Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), userSearchEndedCb); + if (!func.IsEmpty()) { + SWIGV8_VALUE callback_args[] = {V8_STRING_NEW_LOCAL(accountId), + SWIGV8_INTEGER_NEW(state), + V8_STRING_NEW_LOCAL(query), + stringMapVecToJsMapArray(results)}; + func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 4, callback_args); + } + }); + + uv_async_send(&signalAsync); +} + void incomingTrustRequest(const std::string& accountId, const std::string& from, diff --git a/bin/nodejs/nodejs_interface.i b/bin/nodejs/nodejs_interface.i index d1517c4d1669a5ade19a6f436f884733996a4c96..b486c7b1d046f709e997977229463897b05996cd 100644 --- a/bin/nodejs/nodejs_interface.i +++ b/bin/nodejs/nodejs_interface.i @@ -144,6 +144,7 @@ void init(const SWIGV8_VALUE& funcMap){ exportable_callback<ConfigurationSignal::ProfileReceived>(bind(&profileReceived, _1, _2, _3)), exportable_callback<ConfigurationSignal::AccountProfileReceived>(bind(&accountProfileReceived, _1, _2, _3)), //exportable_callback<ConfigurationSignal::IncomingTrustRequest>(bind(&incomingTrustRequest, _1, _2, _3, _4, _5 )), + exportable_callback<ConfigurationSignal::UserSearchEnded>(bind(&userSearchEnded, _1, _2, _3, _4 )), }; const std::map<std::string, SharedCallback> dataTransferEvHandlers = {