Page MenuHomePhabricator

D11725.diff
No OneTemporary

D11725.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
@@ -203,6 +203,9 @@
jsi::Runtime &rt,
jsi::Object siweBackupSecrets) override;
virtual jsi::Value getSIWEBackupSecrets(jsi::Runtime &rt) override;
+ virtual jsi::Value getAllReceivedMessageToDevice(jsi::Runtime &rt) override;
+ virtual jsi::Value
+ removeReceivedMessagesToDevice(jsi::Runtime &rt, jsi::Array ids) 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
@@ -1987,4 +1987,85 @@
job, promise, this->jsInvoker_);
});
}
+
+jsi::Value CommCoreModule::getAllReceivedMessageToDevice(jsi::Runtime &rt) {
+ return createPromiseAsJSIValue(
+ rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [=, &innerRt]() {
+ std::string error;
+ std::vector<ReceivedMessageToDevice> messages;
+
+ try {
+ messages = DatabaseManager::getQueryExecutor()
+ .getAllReceivedMessageToDevice();
+
+ } catch (std::system_error &e) {
+ error = e.what();
+ }
+ auto messagesPtr =
+ std::make_shared<std::vector<ReceivedMessageToDevice>>(
+ std::move(messages));
+
+ this->jsInvoker_->invokeAsync(
+ [&innerRt, messagesPtr, error, promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ return;
+ }
+
+ jsi::Array jsiMessages =
+ jsi::Array(innerRt, messagesPtr->size());
+ size_t writeIdx = 0;
+ for (const ReceivedMessageToDevice &msg : *messagesPtr) {
+ jsi::Object jsiMsg = jsi::Object(innerRt);
+ jsiMsg.setProperty(innerRt, "messageID", msg.message_id);
+ jsiMsg.setProperty(
+ innerRt, "senderDeviceID", msg.sender_device_id);
+ jsiMsg.setProperty(innerRt, "plaintext", msg.plaintext);
+ jsiMsg.setProperty(innerRt, "status", msg.status);
+ jsiMessages.setValueAtIndex(innerRt, writeIdx++, jsiMsg);
+ }
+
+ promise->resolve(std::move(jsiMessages));
+ });
+ };
+ GlobalDBSingleton::instance.scheduleOrRunCancellable(
+ job, promise, this->jsInvoker_);
+ });
+}
+
+jsi::Value CommCoreModule::removeReceivedMessagesToDevice(
+ jsi::Runtime &rt,
+ jsi::Array ids) {
+ std::vector<std::string> msgIDsCPP{};
+ for (auto idx = 0; idx < ids.size(rt); idx++) {
+ std::string msgID = ids.getValueAtIndex(rt, idx).asString(rt).utf8(rt);
+ msgIDsCPP.push_back(msgID);
+ }
+
+ return createPromiseAsJSIValue(
+ rt,
+ [this,
+ msgIDsCPP](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [this, promise, msgIDsCPP]() {
+ std::string error;
+ try {
+ DatabaseManager::getQueryExecutor().removeReceivedMessagesToDevice(
+ msgIDsCPP);
+ } catch (std::system_error &e) {
+ error = e.what();
+ }
+ this->jsInvoker_->invokeAsync([error, promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ } else {
+ promise->resolve(jsi::Value::undefined());
+ }
+ });
+ };
+ GlobalDBSingleton::instance.scheduleOrRunCancellable(
+ job, promise, this->jsInvoker_);
+ });
+}
+
} // namespace comm
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
@@ -202,6 +202,12 @@
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getSIWEBackupSecrets(rt);
}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllReceivedMessageToDevice(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getAllReceivedMessageToDevice(rt);
+}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeReceivedMessagesToDevice(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->removeReceivedMessagesToDevice(rt, args[0].asObject(rt).asArray(rt));
+}
CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
: TurboModule("CommTurboModule", jsInvoker) {
@@ -266,6 +272,8 @@
methodMap_["retrieveBackupKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_retrieveBackupKeys};
methodMap_["setSIWEBackupSecrets"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_setSIWEBackupSecrets};
methodMap_["getSIWEBackupSecrets"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getSIWEBackupSecrets};
+ methodMap_["getAllReceivedMessageToDevice"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getAllReceivedMessageToDevice};
+ methodMap_["removeReceivedMessagesToDevice"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_removeReceivedMessagesToDevice};
}
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
@@ -81,6 +81,8 @@
virtual jsi::Value retrieveBackupKeys(jsi::Runtime &rt, jsi::String backupSecret) = 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;
+ virtual jsi::Value removeReceivedMessagesToDevice(jsi::Runtime &rt, jsi::Array ids) = 0;
};
@@ -590,6 +592,22 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::getSIWEBackupSecrets, jsInvoker_, instance_);
}
+ jsi::Value getAllReceivedMessageToDevice(jsi::Runtime &rt) override {
+ static_assert(
+ bridging::getParameterCount(&T::getAllReceivedMessageToDevice) == 1,
+ "Expected getAllReceivedMessageToDevice(...) to have 1 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::getAllReceivedMessageToDevice, jsInvoker_, instance_);
+ }
+ jsi::Value removeReceivedMessagesToDevice(jsi::Runtime &rt, jsi::Array ids) override {
+ static_assert(
+ bridging::getParameterCount(&T::removeReceivedMessagesToDevice) == 2,
+ "Expected removeReceivedMessagesToDevice(...) to have 2 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::removeReceivedMessagesToDevice, jsInvoker_, instance_, std::move(ids));
+ }
private:
T *instance_;
diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js
--- a/native/schema/CommCoreModuleSchema.js
+++ b/native/schema/CommCoreModuleSchema.js
@@ -25,6 +25,7 @@
import type { ClientDBDraftStoreOperation } from 'lib/types/draft-types.js';
import type { ClientDBMessageInfo } from 'lib/types/message-types.js';
import type { SIWEBackupSecrets } from 'lib/types/siwe-types.js';
+import type { ReceivedMessageToDevice } from 'lib/types/sqlite-types.js';
import type { ClientDBStore } from 'lib/types/store-ops-types';
import type { ClientDBThreadInfo } from 'lib/types/thread-types.js';
@@ -164,6 +165,10 @@
+retrieveBackupKeys: (backupSecret: string) => Promise<string>;
+setSIWEBackupSecrets: (siweBackupSecrets: Object) => Promise<void>;
+getSIWEBackupSecrets: () => Promise<?Object>;
+ +getAllReceivedMessageToDevice: () => Promise<ReceivedMessageToDevice[]>;
+ +removeReceivedMessagesToDevice: (
+ ids: $ReadOnlyArray<string>,
+ ) => Promise<void>;
}
export interface CoreModuleSpec extends Spec {

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 9:54 PM (17 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2565445
Default Alt Text
D11725.diff (8 KB)

Event Timeline