Page MenuHomePhabricator

D13899.diff
No OneTemporary

D13899.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
@@ -280,6 +280,8 @@
jsi::String threadID,
double limit,
double offset) override;
+ virtual jsi::Value
+ getInboundP2PMessagesByID(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
@@ -3213,4 +3213,58 @@
});
}
+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 =
+ 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);
+ }
+
+ promise->resolve(std::move(jsiMessages));
+ });
+ };
+ 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
@@ -244,6 +244,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) {
@@ -322,6 +325,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
@@ -95,6 +95,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;
};
@@ -716,6 +717,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
@@ -210,6 +210,9 @@
limit: number,
offset: number,
) => Promise<Array<ClientDBMessageInfo>>;
+ +getInboundP2PMessagesByID: (
+ ids: $ReadOnlyArray<string>,
+ ) => Promise<Array<InboundP2PMessage>>;
}
export interface CoreModuleSpec extends Spec {

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 9:52 AM (19 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2451113
Default Alt Text
D13899.diff (6 KB)

Event Timeline