diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp --- a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp +++ b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageOperationsUtilities.cpp @@ -4,6 +4,57 @@ #include namespace comm { +ClientDBMessageInfo +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 localID = nullptr; + if (rawMessageInfo.count("localID")) { + localID = + std::make_unique(rawMessageInfo["localID"].asString()); + } + + int type = rawMessageInfo["type"].asInt(); + MessageType messageType = static_cast(type); + int64_t time = rawMessageInfo["time"].asInt(); + + std::unique_ptr futureType = nullptr; + if (messageType == MessageType::UNSUPPORTED) { + futureType = std::make_unique( + rawMessageInfo["unsupportedMessageInfo"]["type"].asInt()); + } + + std::unique_ptr content = nullptr; + if (messageSpecsHolder.find(messageType) != messageSpecsHolder.end()) { + content = messageSpecsHolder.at(messageType) + ->messageContentForClientDB(rawMessageInfo); + } + std::vector mediaVector; + if (messageType == MessageType::IMAGES || + messageType == MessageType::MULTIMEDIA) { + for (const auto &media : rawMessageInfo["media"]) { + mediaVector.push_back( + translateMediaToClientDBMediaInfo(media, id, thread)); + } + } + return { + Message{ + id, + std::move(localID), + thread, + user, + type, + std::move(futureType), + std::move(content), + time}, + std::move(mediaVector)}; +} + Media MessageOperationsUtilities::translateMediaToClientDBMediaInfo( const folly::dynamic &rawMediaInfo, const std::string &container,