Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3154442
D5341.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D5341.diff
View Options
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h
@@ -61,6 +61,9 @@
jsi::Value
setCurrentUserID(jsi::Runtime &rt, const jsi::String &userID) override;
jsi::Value getCurrentUserID(jsi::Runtime &rt) override;
+ jsi::Value
+ setDeviceID(jsi::Runtime &rt, const jsi::String &deviceType) override;
+ jsi::Value getDeviceID(jsi::Runtime &rt) override;
jsi::Value clearSensitiveData(jsi::Runtime &rt) override;
public:
diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
--- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
+++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
@@ -1,4 +1,5 @@
#include "CommCoreModule.h"
+#include "../CryptoTools/DeviceID.h"
#include "DatabaseManager.h"
#include "GRPCStreamHostObject.h"
#include "InternalModules/GlobalDBSingleton.h"
@@ -995,6 +996,50 @@
});
}
+jsi::Value
+CommCoreModule::setDeviceID(jsi::Runtime &rt, const jsi::String &deviceType) {
+ std::string type = deviceType.utf8(rt);
+ std::string deviceID;
+ try {
+ deviceID = DeviceIDGenerator::generateDeviceID(type);
+ } catch (std::invalid_argument &e) {
+ throw jsi::JSError(
+ rt,
+ "setDeviceID: incorrect function argument. Must be one of: "
+ "KEYSERVER, WEB, MOBILE.");
+ }
+ GlobalDBSingleton::instance.scheduleOrRun([&rt, deviceID]() {
+ try {
+ DatabaseManager::getQueryExecutor().setDeviceID(deviceID);
+ } catch (const std::exception &e) {
+ throw jsi::JSError(rt, e.what());
+ }
+ });
+ return jsi::String::createFromUtf8(rt, deviceID);
+}
+
+jsi::Value CommCoreModule::getDeviceID(jsi::Runtime &rt) {
+ return createPromiseAsJSIValue(
+ rt, [this](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ GlobalDBSingleton::instance.scheduleOrRun([this, &innerRt, promise]() {
+ std::string error;
+ std::string result;
+ try {
+ result = DatabaseManager::getQueryExecutor().getDeviceID();
+ } catch (const std::exception &e) {
+ error = e.what();
+ }
+ this->jsInvoker_->invokeAsync([&innerRt, error, result, promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ } else {
+ promise->resolve(jsi::String::createFromUtf8(innerRt, result));
+ }
+ });
+ });
+ });
+}
+
jsi::Value CommCoreModule::clearSensitiveData(jsi::Runtime &rt) {
return createPromiseAsJSIValue(
rt, [this](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
diff --git a/native/cpp/CommonCpp/_generated/NativeModules.h b/native/cpp/CommonCpp/_generated/NativeModules.h
--- a/native/cpp/CommonCpp/_generated/NativeModules.h
+++ b/native/cpp/CommonCpp/_generated/NativeModules.h
@@ -40,6 +40,8 @@
virtual jsi::Value clearNotifyToken(jsi::Runtime &rt) = 0;
virtual jsi::Value setCurrentUserID(jsi::Runtime &rt, const jsi::String &userID) = 0;
virtual jsi::Value getCurrentUserID(jsi::Runtime &rt) = 0;
+virtual jsi::Value setDeviceID(jsi::Runtime &rt, const jsi::String &deviceType) = 0;
+virtual jsi::Value getDeviceID(jsi::Runtime &rt) = 0;
virtual jsi::Value clearSensitiveData(jsi::Runtime &rt) = 0;
};
diff --git a/native/cpp/CommonCpp/_generated/NativeModules.cpp b/native/cpp/CommonCpp/_generated/NativeModules.cpp
--- a/native/cpp/CommonCpp/_generated/NativeModules.cpp
+++ b/native/cpp/CommonCpp/_generated/NativeModules.cpp
@@ -80,6 +80,12 @@
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCurrentUserID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getCurrentUserID(rt);
}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setDeviceID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->setDeviceID(rt, args[0].getString(rt));
+}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getDeviceID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getDeviceID(rt);
+}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearSensitiveData(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->clearSensitiveData(rt);
}
@@ -108,6 +114,8 @@
methodMap_["clearNotifyToken"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearNotifyToken};
methodMap_["setCurrentUserID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setCurrentUserID};
methodMap_["getCurrentUserID"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCurrentUserID};
+ methodMap_["setDeviceID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setDeviceID};
+ methodMap_["getDeviceID"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getDeviceID};
methodMap_["clearSensitiveData"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearSensitiveData};
}
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -50,6 +50,8 @@
+clearNotifyToken: () => Promise<void>;
+setCurrentUserID: (userID: string) => Promise<void>;
+getCurrentUserID: () => Promise<string>;
+ +setDeviceID: (deviceType: string) => Promise<string>;
+ +getDeviceID: () => Promise<String>;
+clearSensitiveData: () => Promise<void>;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 6, 8:30 AM (19 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2429776
Default Alt Text
D5341.diff (5 KB)
Attached To
Mode
D5341: [native] Add JSI functions for creating/setting and fetching device ID
Attached
Detach File
Event Timeline
Log In to Comment