Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3245265
D4616.id14833.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D4616.id14833.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
@@ -58,6 +58,8 @@
jsi::Value
setNotifyToken(jsi::Runtime &rt, const jsi::String &token) override;
jsi::Value clearNotifyToken(jsi::Runtime &rt) override;
+ jsi::String
+ generateDeviceID(jsi::Runtime &rt, const jsi::String &type) override;
public:
CommCoreModule(std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
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
@@ -14,6 +14,8 @@
#include <ReactCommon/TurboModuleUtils.h>
#include <future>
+#include "../CryptoTools/Tools.h"
+
namespace comm {
using namespace facebook::react;
@@ -955,4 +957,24 @@
});
};
+jsi::String
+CommCoreModule::generateDeviceID(jsi::Runtime &rt, const jsi::String &jsType) {
+ std::string id = "";
+ std::string type = jsType.utf8(rt);
+ if (type == "KEYSERVER") {
+ id = "ks:";
+ } else if (type == "WEB") {
+ id = "web:";
+ } else if (type == "MOBILE") {
+ id = "mobile:";
+ } else {
+ throw jsi::JSError(
+ rt,
+ "getDeviceID: incorrect string. Must be one of: KEYSERVER, WEB, "
+ "MOBILE.");
+ }
+ id += crypto::Tools::generateRandomHexString(64);
+ return jsi::String::createFromUtf8(rt, id);
+}
+
} // namespace comm
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
@@ -38,6 +38,7 @@
virtual double getCodeVersion(jsi::Runtime &rt) = 0;
virtual jsi::Value setNotifyToken(jsi::Runtime &rt, const jsi::String &token) = 0;
virtual jsi::Value clearNotifyToken(jsi::Runtime &rt) = 0;
+virtual jsi::String generateDeviceID(jsi::Runtime &rt, const jsi::String &jsType) = 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
@@ -72,6 +72,9 @@
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearNotifyToken(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->clearNotifyToken(rt);
}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_generateDeviceID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->generateDeviceID(rt, args[0].getString(rt));
+}
CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
: TurboModule("CommTurboModule", jsInvoker) {
@@ -95,6 +98,7 @@
methodMap_["getCodeVersion"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getCodeVersion};
methodMap_["setNotifyToken"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setNotifyToken};
methodMap_["clearNotifyToken"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_clearNotifyToken};
+ methodMap_["generateDeviceID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_generateDeviceID};
}
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -48,6 +48,7 @@
+getCodeVersion: () => number;
+setNotifyToken: (token: string) => Promise<void>;
+clearNotifyToken: () => Promise<void>;
+ +generateDeviceID: (jsType: string) => string;
}
export default (TurboModuleRegistry.getEnforcing<Spec>(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 15, 5:31 PM (20 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2494926
Default Alt Text
D4616.id14833.diff (3 KB)
Attached To
Mode
D4616: [native] Add a function for creating unique device ID on mobile in cpp/jsi
Attached
Detach File
Event Timeline
Log In to Comment