Page MenuHomePhabricator

D11735.id40004.diff
No OneTemporary

D11735.id40004.diff

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
@@ -189,6 +189,7 @@
virtual jsi::Value setSIWEBackupSecrets(
jsi::Runtime &rt,
jsi::Object siweBackupSecrets) override;
+ virtual jsi::Value retrieveLatestSIWEBackupData(jsi::Runtime &rt) override;
virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) override;
virtual jsi::Value getAllReceivedMessageToDevice(jsi::Runtime &rt) override;
virtual jsi::Value
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
@@ -2023,6 +2023,15 @@
});
}
+jsi::Value CommCoreModule::retrieveLatestSIWEBackupData(jsi::Runtime &rt) {
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ auto currentID = RustPromiseManager::instance.addPromise(
+ {promise, this->jsInvoker_, innerRt});
+ ::retrieveLatestSIWEBackupData(currentID);
+ });
+}
+
jsi::Value CommCoreModule::setSIWEBackupSecrets(
jsi::Runtime &rt,
jsi::Object siweBackupSecrets) {
diff --git a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp
--- a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp
+++ b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp
@@ -169,6 +169,9 @@
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->retrieveBackupKeys(rt, args[0].asString(rt));
}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveLatestSIWEBackupData(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->retrieveLatestSIWEBackupData(rt);
+}
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setSIWEBackupSecrets(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->setSIWEBackupSecrets(rt, args[0].asObject(rt));
}
@@ -234,6 +237,7 @@
methodMap_["restoreBackup"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackup};
methodMap_["restoreBackupData"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_restoreBackupData};
methodMap_["retrieveBackupKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys};
+ methodMap_["retrieveLatestSIWEBackupData"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveLatestSIWEBackupData};
methodMap_["setSIWEBackupSecrets"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setSIWEBackupSecrets};
methodMap_["getSIWEBackupSecrets"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets};
methodMap_["getAllReceivedMessageToDevice"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllReceivedMessageToDevice};
diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h
--- a/native/cpp/CommonCpp/_generated/commJSI.h
+++ b/native/cpp/CommonCpp/_generated/commJSI.h
@@ -70,6 +70,7 @@
virtual jsi::Value restoreBackup(jsi::Runtime &rt, jsi::String backupSecret) = 0;
virtual jsi::Value restoreBackupData(jsi::Runtime &rt, jsi::String backupID, jsi::String backupDataKey, jsi::String backupLogDataKey) = 0;
virtual jsi::Value retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret) = 0;
+ virtual jsi::Value retrieveLatestSIWEBackupData(jsi::Runtime &rt) = 0;
virtual jsi::Value setSIWEBackupSecrets(jsi::Runtime &rt, jsi::Object siweBackupSecrets) = 0;
virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) = 0;
virtual jsi::Value getAllReceivedMessageToDevice(jsi::Runtime &rt) = 0;
@@ -495,6 +496,14 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::retrieveBackupKeys, jsInvoker_, instance_, std::move(backupSecret));
}
+ jsi::Value retrieveLatestSIWEBackupData(jsi::Runtime &rt) override {
+ static_assert(
+ bridging::getParameterCount(&T::retrieveLatestSIWEBackupData) == 1,
+ "Expected retrieveLatestSIWEBackupData(...) to have 1 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::retrieveLatestSIWEBackupData, jsInvoker_, instance_);
+ }
jsi::Value setSIWEBackupSecrets(jsi::Runtime &rt, jsi::Object siweBackupSecrets) override {
static_assert(
bridging::getParameterCount(&T::setSIWEBackupSecrets) == 2,
diff --git a/native/native_rust_library/src/backup.rs b/native/native_rust_library/src/backup.rs
--- a/native/native_rust_library/src/backup.rs
+++ b/native/native_rust_library/src/backup.rs
@@ -179,6 +179,45 @@
void_callback(String::new(), promise_id);
});
}
+
+ pub fn retrieve_latest_siwe_backup_data(promise_id: u32) {
+ RUNTIME.spawn(async move {
+ let result = download_latest_backup_id()
+ .await
+ .map_err(|err| err.to_string());
+
+ let result = match result {
+ Ok(result) => result,
+ Err(error) => {
+ string_callback(error, promise_id, "".to_string());
+ return;
+ }
+ };
+
+ let LatestBackupIDResponse {
+ backup_id,
+ siwe_backup_msg,
+ } = result;
+
+ let siwe_backup_data = match siwe_backup_msg {
+ Some(siwe_backup_msg_value) => SIWEBackupData {
+ backup_id,
+ siwe_backup_msg: siwe_backup_msg_value,
+ },
+ None => {
+ string_callback(
+ "Backup message unavailable".to_string(),
+ promise_id,
+ "".to_string(),
+ );
+ return;
+ }
+ };
+
+ let serialize_result = serde_json::to_string(&siwe_backup_data);
+ handle_string_result_as_callback(serialize_result, promise_id);
+ });
+ }
}
pub async fn create_userkeys_compaction(
@@ -227,6 +266,30 @@
download_backup_data(backup_keys).await
}
+async fn download_latest_backup_id(
+) -> Result<LatestBackupIDResponse, Box<dyn Error>> {
+ let backup_client = BackupClient::new(BACKUP_SOCKET_ADDR)?;
+ let user_identity = get_user_identity_from_secure_store()?;
+
+ let latest_backup_descriptor = BackupDescriptor::Latest {
+ username: user_identity.user_id.clone(),
+ };
+
+ let backup_id_response = backup_client
+ .download_backup_data(&latest_backup_descriptor, RequestedData::BackupID)
+ .await?;
+
+ let LatestBackupIDResponse {
+ backup_id,
+ siwe_backup_msg,
+ } = serde_json::from_slice(&backup_id_response)?;
+
+ Ok(LatestBackupIDResponse {
+ backup_id,
+ siwe_backup_msg,
+ })
+}
+
async fn download_backup_keys(
backup_secret: String,
) -> Result<BackupKeysResult, Box<dyn Error>> {
@@ -336,6 +399,12 @@
backup_log_data_key: String,
}
+#[derive(Debug, Serialize)]
+struct SIWEBackupData {
+ backup_id: String,
+ siwe_backup_msg: String,
+}
+
struct CompactionDownloadResult {
backup_id: String,
backup_restoration_path: PathBuf,
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
@@ -372,6 +372,9 @@
#[cxx_name = "retrieveBackupKeys"]
fn retrieve_backup_keys(backup_secret: String, promise_id: u32);
+
+ #[cxx_name = "retrieveLatestSIWEBackupData"]
+ fn retrieve_latest_siwe_backup_data(promise_id: u32);
}
// Secure store
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -130,6 +130,7 @@
backupLogDataKey: string,
) => Promise<void>;
+retrieveBackupKeys: (backupSecret: string) => Promise<string>;
+ +retrieveLatestSIWEBackupData: () => Promise<string>;
+setSIWEBackupSecrets: (siweBackupSecrets: Object) => Promise<void>;
+getSIWEBackupSecrets: () => Promise<?Object>;
+getAllReceivedMessageToDevice: () => Promise<ReceivedMessageToDevice[]>;

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 5:23 PM (16 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2563246
Default Alt Text
D11735.id40004.diff (8 KB)

Event Timeline