Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32564165
D10864.1767366433.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
D10864.1767366433.diff
View Options
diff --git a/native/cpp/CommonCpp/NativeModules/CommRustModule.h b/native/cpp/CommonCpp/NativeModules/CommRustModule.h
--- a/native/cpp/CommonCpp/NativeModules/CommRustModule.h
+++ b/native/cpp/CommonCpp/NativeModules/CommRustModule.h
@@ -92,6 +92,12 @@
jsi::String authAccessToken,
jsi::String userID,
std::optional<double> sinceTimestamp) override;
+ virtual jsi::Value updateDeviceList(
+ jsi::Runtime &rt,
+ jsi::String authUserID,
+ jsi::String authDeviceID,
+ jsi::String authAccessToken,
+ jsi::String updatePayload) override;
public:
CommRustModule(std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
diff --git a/native/cpp/CommonCpp/NativeModules/CommRustModule.cpp b/native/cpp/CommonCpp/NativeModules/CommRustModule.cpp
--- a/native/cpp/CommonCpp/NativeModules/CommRustModule.cpp
+++ b/native/cpp/CommonCpp/NativeModules/CommRustModule.cpp
@@ -441,4 +441,36 @@
});
}
+jsi::Value CommRustModule::updateDeviceList(
+ jsi::Runtime &rt,
+ jsi::String authUserID,
+ jsi::String authDeviceID,
+ jsi::String authAccessToken,
+ jsi::String updatePayload) {
+ auto authUserIDRust = jsiStringToRustString(authUserID, rt);
+ auto authDeviceIDRust = jsiStringToRustString(authDeviceID, rt);
+ auto authAccessTokenRust = jsiStringToRustString(authAccessToken, rt);
+ auto updatePayloadRust = jsiStringToRustString(updatePayload, rt);
+ return createPromiseAsJSIValue(
+ rt, [=, this](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ std::string error;
+ try {
+ auto currentID = RustPromiseManager::instance.addPromise(
+ {promise, this->jsInvoker_, innerRt});
+ identityUpdateDeviceList(
+ authUserIDRust,
+ authDeviceIDRust,
+ authAccessTokenRust,
+ updatePayloadRust,
+ currentID);
+ } catch (const std::exception &e) {
+ error = e.what();
+ };
+ if (!error.empty()) {
+ this->jsInvoker_->invokeAsync(
+ [error, promise]() { promise->reject(error); });
+ }
+ });
+}
+
} // namespace comm
diff --git a/native/cpp/CommonCpp/_generated/rustJSI-generated.cpp b/native/cpp/CommonCpp/_generated/rustJSI-generated.cpp
--- a/native/cpp/CommonCpp/_generated/rustJSI-generated.cpp
+++ b/native/cpp/CommonCpp/_generated/rustJSI-generated.cpp
@@ -48,6 +48,9 @@
static jsi::Value __hostFunction_CommRustModuleSchemaCxxSpecJSI_getDeviceListForUser(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommRustModuleSchemaCxxSpecJSI *>(&turboModule)->getDeviceListForUser(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt), args[4].isNull() || args[4].isUndefined() ? std::nullopt : std::make_optional(args[4].asNumber()));
}
+static jsi::Value __hostFunction_CommRustModuleSchemaCxxSpecJSI_updateDeviceList(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommRustModuleSchemaCxxSpecJSI *>(&turboModule)->updateDeviceList(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt));
+}
CommRustModuleSchemaCxxSpecJSI::CommRustModuleSchemaCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
: TurboModule("CommRustTurboModule", jsInvoker) {
@@ -63,6 +66,7 @@
methodMap_["uploadOneTimeKeys"] = MethodMetadata {5, __hostFunction_CommRustModuleSchemaCxxSpecJSI_uploadOneTimeKeys};
methodMap_["getKeyserverKeys"] = MethodMetadata {4, __hostFunction_CommRustModuleSchemaCxxSpecJSI_getKeyserverKeys};
methodMap_["getDeviceListForUser"] = MethodMetadata {5, __hostFunction_CommRustModuleSchemaCxxSpecJSI_getDeviceListForUser};
+ methodMap_["updateDeviceList"] = MethodMetadata {4, __hostFunction_CommRustModuleSchemaCxxSpecJSI_updateDeviceList};
}
diff --git a/native/cpp/CommonCpp/_generated/rustJSI.h b/native/cpp/CommonCpp/_generated/rustJSI.h
--- a/native/cpp/CommonCpp/_generated/rustJSI.h
+++ b/native/cpp/CommonCpp/_generated/rustJSI.h
@@ -32,6 +32,7 @@
virtual jsi::Value uploadOneTimeKeys(jsi::Runtime &rt, jsi::String authUserID, jsi::String authDeviceID, jsi::String authAccessToken, jsi::Array contentOneTimePreKeys, jsi::Array notifOneTimePreKeys) = 0;
virtual jsi::Value getKeyserverKeys(jsi::Runtime &rt, jsi::String authUserID, jsi::String authDeviceID, jsi::String authAccessToken, jsi::String keyserverID) = 0;
virtual jsi::Value getDeviceListForUser(jsi::Runtime &rt, jsi::String authUserID, jsi::String authDeviceID, jsi::String authAccessToken, jsi::String userID, std::optional<double> sinceTimestamp) = 0;
+ virtual jsi::Value updateDeviceList(jsi::Runtime &rt, jsi::String authUserID, jsi::String authDeviceID, jsi::String authAccessToken, jsi::String updatePayload) = 0;
};
@@ -149,6 +150,14 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::getDeviceListForUser, jsInvoker_, instance_, std::move(authUserID), std::move(authDeviceID), std::move(authAccessToken), std::move(userID), std::move(sinceTimestamp));
}
+ jsi::Value updateDeviceList(jsi::Runtime &rt, jsi::String authUserID, jsi::String authDeviceID, jsi::String authAccessToken, jsi::String updatePayload) override {
+ static_assert(
+ bridging::getParameterCount(&T::updateDeviceList) == 5,
+ "Expected updateDeviceList(...) to have 5 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::updateDeviceList, jsInvoker_, instance_, std::move(authUserID), std::move(authDeviceID), std::move(authAccessToken), std::move(updatePayload));
+ }
private:
T *instance_;
diff --git a/native/native_rust_library/src/lib.rs b/native/native_rust_library/src/lib.rs
--- a/native/native_rust_library/src/lib.rs
+++ b/native/native_rust_library/src/lib.rs
@@ -184,6 +184,15 @@
promise_id: u32,
);
+ #[cxx_name = "identityUpdateDeviceList"]
+ fn update_device_list(
+ auth_user_id: String,
+ auth_device_id: String,
+ auth_access_token: String,
+ update_payload: String,
+ promise_id: u32,
+ );
+
// Argon2
#[cxx_name = "compute_backup_key"]
fn compute_backup_key_str(
@@ -1297,6 +1306,49 @@
Ok(payload)
}
+fn update_device_list(
+ auth_user_id: String,
+ auth_device_id: String,
+ auth_access_token: String,
+ update_payload: String,
+ promise_id: u32,
+) {
+ RUNTIME.spawn(async move {
+ let auth_info = AuthInfo {
+ access_token: auth_access_token,
+ user_id: auth_user_id,
+ device_id: auth_device_id,
+ };
+ let result = update_device_list_helper(auth_info, update_payload).await;
+ handle_void_result_as_callback(result, promise_id);
+ });
+}
+
+async fn update_device_list_helper(
+ auth_info: AuthInfo,
+ update_payload: String,
+) -> Result<(), Error> {
+ let mut identity_client = get_auth_client(
+ IDENTITY_SOCKET_ADDR,
+ auth_info.user_id,
+ auth_info.device_id,
+ auth_info.access_token,
+ CODE_VERSION,
+ DEVICE_TYPE.as_str_name().to_lowercase(),
+ )
+ .await?;
+
+ let update_request = UpdateDeviceListRequest {
+ new_device_list: update_payload,
+ };
+
+ identity_client
+ .update_device_list_for_user(update_request)
+ .await?;
+
+ Ok(())
+}
+
#[derive(
Debug, derive_more::Display, derive_more::From, derive_more::Error,
)]
diff --git a/native/schema/CommRustModuleSchema.js b/native/schema/CommRustModuleSchema.js
--- a/native/schema/CommRustModuleSchema.js
+++ b/native/schema/CommRustModuleSchema.js
@@ -87,6 +87,12 @@
userID: string,
sinceTimestamp: ?number,
) => Promise<string>;
+ +updateDeviceList: (
+ authUserID: string,
+ authDeviceID: string,
+ authAccessToken: string,
+ updatePayload: string,
+ ) => Promise<void>;
}
export default (TurboModuleRegistry.getEnforcing<Spec>(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 2, 3:07 PM (11 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5878326
Default Alt Text
D10864.1767366433.diff (7 KB)
Attached To
Mode
D10864: [native] Expose UpdateDeviceList RPC to JS
Attached
Detach File
Event Timeline
Log In to Comment