Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3332205
D13899.id45737.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D13899.id45737.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
@@ -248,6 +248,8 @@
virtual jsi::Value
getOutboundP2PMessagesByID(jsi::Runtime &rt, jsi::Array ids) override;
virtual jsi::Value getAllOutboundP2PMessages(jsi::Runtime &rt) override;
+ virtual jsi::Value
+ getInboundP2PMessagesByID(jsi::Runtime &rt, jsi::Array ids) override;
virtual jsi::Value markOutboundP2PMessageAsSent(
jsi::Runtime &rt,
jsi::String messageID,
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
@@ -882,6 +882,23 @@
return encryptedDataJSI;
}
+jsi::Array parseInboundingMessages(
+ jsi::Runtime &rt,
+ std::shared_ptr<std::vector<InboundP2PMessage>> messagesPtr) {
+ jsi::Array jsiMessages = jsi::Array(rt, messagesPtr->size());
+ size_t writeIdx = 0;
+ for (const InboundP2PMessage &msg : *messagesPtr) {
+ jsi::Object jsiMsg = jsi::Object(rt);
+ jsiMsg.setProperty(rt, "messageID", msg.message_id);
+ jsiMsg.setProperty(rt, "senderDeviceID", msg.sender_device_id);
+ jsiMsg.setProperty(rt, "plaintext", msg.plaintext);
+ jsiMsg.setProperty(rt, "status", msg.status);
+ jsiMsg.setProperty(rt, "senderUserID", msg.sender_user_id);
+ jsiMessages.setValueAtIndex(rt, writeIdx++, jsiMsg);
+ }
+ return jsiMessages;
+}
+
jsi::Value
CommCoreModule::getOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) {
return createPromiseAsJSIValue(
@@ -2729,19 +2746,7 @@
}
jsi::Array jsiMessages =
- jsi::Array(innerRt, messagesPtr->size());
- size_t writeIdx = 0;
- for (const InboundP2PMessage &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);
- jsiMsg.setProperty(
- innerRt, "senderUserID", msg.sender_user_id);
- jsiMessages.setValueAtIndex(innerRt, writeIdx++, jsiMsg);
- }
+ parseInboundingMessages(innerRt, messagesPtr);
promise->resolve(std::move(jsiMessages));
});
@@ -2784,6 +2789,48 @@
});
}
+jsi::Value
+CommCoreModule::getInboundP2PMessagesByID(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, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
+ taskType job = [=, &innerRt]() {
+ std::string error;
+ std::vector<InboundP2PMessage> messages;
+
+ try {
+ messages =
+ DatabaseManager::getQueryExecutor().getInboundP2PMessagesByID(
+ msgIDsCPP);
+ } catch (std::system_error &e) {
+ error = e.what();
+ }
+ auto messagesPtr = std::make_shared<std::vector<InboundP2PMessage>>(
+ std::move(messages));
+
+ this->jsInvoker_->invokeAsync(
+ [&innerRt, messagesPtr, error, promise]() {
+ if (error.size()) {
+ promise->reject(error);
+ return;
+ }
+
+ jsi::Array jsiMessages =
+ parseInboundingMessages(innerRt, messagesPtr);
+
+ promise->resolve(std::move(jsiMessages));
+ });
+ };
+ GlobalDBSingleton::instance.scheduleOrRunCancellable(
+ job, promise, this->jsInvoker_);
+ });
+}
+
jsi::Value
CommCoreModule::getOutboundP2PMessagesByID(jsi::Runtime &rt, jsi::Array ids) {
std::vector<std::string> msgIDsCPP{};
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
@@ -241,6 +241,9 @@
static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_fetchMessages(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->fetchMessages(rt, args[0].asString(rt), args[1].asNumber(), args[2].asNumber());
}
+static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getInboundP2PMessagesByID(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
+ return static_cast<CommCoreModuleSchemaCxxSpecJSI *>(&turboModule)->getInboundP2PMessagesByID(rt, args[0].asObject(rt).asArray(rt));
+}
CommCoreModuleSchemaCxxSpecJSI::CommCoreModuleSchemaCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
: TurboModule("CommTurboModule", jsInvoker) {
@@ -318,6 +321,7 @@
methodMap_["getRelatedMessages"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getRelatedMessages};
methodMap_["searchMessages"] = MethodMetadata {4, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_searchMessages};
methodMap_["fetchMessages"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_fetchMessages};
+ methodMap_["getInboundP2PMessagesByID"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getInboundP2PMessagesByID};
}
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
@@ -94,6 +94,7 @@
virtual jsi::Value getRelatedMessages(jsi::Runtime &rt, jsi::String messageID) = 0;
virtual jsi::Value searchMessages(jsi::Runtime &rt, jsi::String query, jsi::String threadID, std::optional<jsi::String> timestampCursor, std::optional<jsi::String> messageIDCursor) = 0;
virtual jsi::Value fetchMessages(jsi::Runtime &rt, jsi::String threadID, double limit, double offset) = 0;
+ virtual jsi::Value getInboundP2PMessagesByID(jsi::Runtime &rt, jsi::Array ids) = 0;
};
@@ -707,6 +708,14 @@
return bridging::callFromJs<jsi::Value>(
rt, &T::fetchMessages, jsInvoker_, instance_, std::move(threadID), std::move(limit), std::move(offset));
}
+ jsi::Value getInboundP2PMessagesByID(jsi::Runtime &rt, jsi::Array ids) override {
+ static_assert(
+ bridging::getParameterCount(&T::getInboundP2PMessagesByID) == 2,
+ "Expected getInboundP2PMessagesByID(...) to have 2 parameters");
+
+ return bridging::callFromJs<jsi::Value>(
+ rt, &T::getInboundP2PMessagesByID, 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
@@ -181,6 +181,9 @@
+getSIWEBackupSecrets: () => Promise<?Object>;
+getAllInboundP2PMessages: () => Promise<Array<InboundP2PMessage>>;
+removeInboundP2PMessages: (ids: $ReadOnlyArray<string>) => Promise<void>;
+ +getInboundP2PMessagesByID: (
+ ids: $ReadOnlyArray<string>,
+ ) => Promise<Array<InboundP2PMessage>>;
+getOutboundP2PMessagesByID: (
ids: $ReadOnlyArray<string>,
) => Promise<Array<OutboundP2PMessage>>;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 21, 11:12 PM (18 h, 12 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2558892
Default Alt Text
D13899.id45737.diff (7 KB)
Attached To
Mode
D13899: [native] Implement getInboundP2PMessagesByID query in JSI
Attached
Detach File
Event Timeline
Log In to Comment