Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3155592
D5341.id17483.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.id17483.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 "../../../native_rust_library/lib.rs.h"
#include "DatabaseManager.h"
#include "GRPCStreamHostObject.h"
#include "InternalModules/GlobalDBSingleton.h"
@@ -995,6 +996,33 @@
});
}
+jsi::Value
+CommCoreModule::setDeviceID(jsi::Runtime &rt, const jsi::String &deviceType) {
+ std::string id = "";
+ std::string type = deviceType.utf8(rt);
+ rust::String deviceID;
+ if (type == "KEYSERVER") {
+ deviceID = generate_device_id(DeviceType::KEYSERVER);
+ } else if (type == "WEB") {
+ deviceID = generate_device_id(DeviceType::WEB);
+ } else if (type == "MOBILE") {
+ deviceID = generate_device_id(DeviceType::MOBILE);
+ } else {
+ throw jsi::JSError(
+ rt,
+ "generateDeviceID: incorrect function argument. Must be one of: "
+ "KEYSERVER, WEB, MOBILE.");
+ }
+ std::string deviceIDstr = std::string(deviceID.c_str());
+ DatabaseManager::getQueryExecutor().setDeviceID(deviceIDstr);
+ return jsi::String::createFromUtf8(rt, deviceIDstr);
+}
+
+jsi::Value CommCoreModule::getDeviceID(jsi::Runtime &rt) {
+ return jsi::String::createFromUtf8(
+ rt, DatabaseManager::getQueryExecutor().getDeviceID());
+}
+
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, 11:04 AM (19 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2430660
Default Alt Text
D5341.id17483.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