Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32322533
D3941.1765301593.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D3941.1765301593.diff
View Options
diff --git a/native/android/app/CMakeLists.txt b/native/android/app/CMakeLists.txt
--- a/native/android/app/CMakeLists.txt
+++ b/native/android/app/CMakeLists.txt
@@ -72,6 +72,8 @@
# comm native mutual code
../../cpp/CommonCpp/NativeModules
../../cpp/CommonCpp/NativeModules/InternalModules
+ ../../cpp/CommonCpp/NativeModules/MessageOperationsUtilities
+ ../../cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs
../../cpp/CommonCpp/DatabaseManagers
../../cpp/CommonCpp/Tools
../../cpp/CommonCpp/grpc/_generated
@@ -121,7 +123,10 @@
./build/third-party-ndk/folly/folly/String.cpp
./build/third-party-ndk/folly/folly/portability/SysUio.cpp
./build/third-party-ndk/folly/folly/net/NetOps.cpp
-
+ ./build/third-party-ndk/folly/folly/dynamic.cpp
+ ./build/third-party-ndk/folly/folly/json.cpp
+ ./build/third-party-ndk/folly/folly/json_pointer.cpp
+ ./build/third-party-ndk/folly/folly/Unicode.cpp
# double-conversion
${DOUBLE_CONVERSION_SOURCES}
diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.h
new file mode 100644
--- /dev/null
+++ b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "../../DatabaseManagers/DatabaseManager.h"
+#include "../../DatabaseManagers/entities/Media.h"
+#include "../../DatabaseManagers/entities/Message.h"
+
+#include <folly/dynamic.h>
+#include <string>
+#include <vector>
+
+namespace comm {
+class MessageOperationsUtilities {
+public:
+ static std::pair<Message, std::vector<Media>>
+ translateRawMessageInfoToClientDBMessageInfo(
+ const folly::dynamic &rawMessageInfo);
+ static Media translateMediaToClientDBMediaInfo(
+ const folly::dynamic &rawMediaInfo,
+ const std::string &container,
+ const std::string &thread);
+ static std::vector<std::pair<Message, std::vector<Media>>>
+ translateStringToClientDBMessageInfo(std::string rawMessageInfoString);
+ static void storeNotification(std::string rawMessageInfoString);
+};
+} // namespace comm
diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp
new file mode 100644
--- /dev/null
+++ b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp
@@ -0,0 +1,110 @@
+#include "MessageOperationsUtilities.h"
+#include "MessageSpecs.h"
+
+#include <folly/String.h>
+#include <folly/json.h>
+#include <stdexcept>
+
+namespace comm {
+std::pair<Message, std::vector<Media>>
+MessageOperationsUtilities::translateRawMessageInfoToClientDBMessageInfo(
+ const folly::dynamic &rawMessageInfo) {
+ std::string id = rawMessageInfo.count("id")
+ ? rawMessageInfo["id"].asString()
+ : rawMessageInfo["localID"].asString();
+ std::string thread = rawMessageInfo["threadID"].asString();
+ std::string user = rawMessageInfo["creatorID"].asString();
+ std::unique_ptr<std::string> localID = rawMessageInfo.count("localID")
+ ? std::make_unique<std::string>(rawMessageInfo["localID"].asString())
+ : nullptr;
+ int type = rawMessageInfo["type"].asInt();
+ MessageType messageType = static_cast<MessageType>(type);
+ int64_t time = rawMessageInfo["time"].asInt();
+ std::unique_ptr<int> futureType = (messageType == MessageType::UNSUPPORTED)
+ ? std::make_unique<int>(
+ rawMessageInfo["unsupportedMessageInfo"]["type"].asInt())
+ : nullptr;
+ std::unique_ptr<std::string> content =
+ messageSpecsHolder.find(messageType) != messageSpecsHolder.end()
+ ? messageSpecsHolder.at(messageType)
+ ->messageContentForClientDB(rawMessageInfo)
+ : nullptr;
+ std::vector<Media> mediaInfos;
+ if (messageType == MessageType::IMAGES ||
+ messageType == MessageType::MULTIMEDIA) {
+ for (const auto &rawMediaInfo : rawMessageInfo["media"]) {
+ mediaInfos.push_back(
+ translateMediaToClientDBMediaInfo(rawMediaInfo, id, thread));
+ }
+ }
+ return {
+ Message{
+ id,
+ std::move(localID),
+ std::move(thread),
+ std::move(user),
+ type,
+ std::move(futureType),
+ std::move(content),
+ time},
+ std::move(mediaInfos)};
+}
+
+Media MessageOperationsUtilities::translateMediaToClientDBMediaInfo(
+ const folly::dynamic &rawMediaInfo,
+ const std::string &container,
+ const std::string &thread) {
+ std::string id = rawMediaInfo["id"].asString();
+ std::string uri = rawMediaInfo["uri"].asString();
+ std::string type = rawMediaInfo["type"].asString();
+ folly::dynamic extrasData =
+ folly::dynamic::object("dimensions", rawMediaInfo["dimensions"])(
+ "loop", (type == "video") ? rawMediaInfo["loop"] : false);
+ if (rawMediaInfo.count("localMediaSelection")) {
+ extrasData["local_media_selection"] = rawMediaInfo["localMediaSelection"];
+ }
+ std::string extras = folly::toJson(extrasData);
+ return Media{
+ std::move(id),
+ std::move(container),
+ std::move(thread),
+ std::move(uri),
+ std::move(type),
+ std::move(extras)};
+}
+
+std::vector<std::pair<Message, std::vector<Media>>>
+MessageOperationsUtilities::translateStringToClientDBMessageInfo(
+ std::string rawMessageInfoString) {
+ folly::dynamic rawMessageInfos =
+ folly::parseJson(folly::trimWhitespace(rawMessageInfoString));
+ if (!rawMessageInfos.isArray()) {
+ throw std::runtime_error(
+ "messageInfos is expected to be an array of JSON objects");
+ }
+ std::vector<std::pair<Message, std::vector<Media>>> clientDBMessageInfos;
+ for (const auto &messageInfo : rawMessageInfos) {
+ if (!messageInfo.isObject()) {
+ throw std::runtime_error(
+ "encountered messageInfos element that is not JSON object");
+ }
+ clientDBMessageInfos.push_back(
+ translateRawMessageInfoToClientDBMessageInfo(messageInfo));
+ }
+ return clientDBMessageInfos;
+}
+
+void MessageOperationsUtilities::storeNotification(
+ std::string rawMessageInfoString) {
+ std::vector<std::pair<Message, std::vector<Media>>> clientDBMessageInfos =
+ translateStringToClientDBMessageInfo(rawMessageInfoString);
+ for (const auto &clientDBMessageInfo : clientDBMessageInfos) {
+ DatabaseManager::getQueryExecutor().replaceMessage(
+ clientDBMessageInfo.first);
+ for (const auto &mediaInfo : clientDBMessageInfo.second) {
+ DatabaseManager::getQueryExecutor().replaceMedia(mediaInfo);
+ }
+ }
+}
+
+} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 9, 5:33 PM (3 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5856174
Default Alt Text
D3941.1765301593.diff (6 KB)
Attached To
Mode
D3941: Implement interface for translation from raw message string into SQLite database entities
Attached
Detach File
Event Timeline
Log In to Comment