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 @@ -6,6 +6,50 @@ #include namespace comm { +std::pair> +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 = rawMessageInfo.count("localID") + ? std::make_unique(rawMessageInfo["localID"].asString()) + : nullptr; + int type = rawMessageInfo["type"].asInt(); + MessageType messageType = static_cast(type); + int64_t time = rawMessageInfo["time"].asInt(); + std::unique_ptr futureType = (messageType == MessageType::UNSUPPORTED) + ? std::make_unique( + rawMessageInfo["unsupportedMessageInfo"]["type"].asInt()) + : nullptr; + std::unique_ptr content = + messageSpecsHolder.find(messageType) != messageSpecsHolder.end() + ? messageSpecsHolder.at(messageType) + ->messageContentForClientDB(rawMessageInfo) + : nullptr; + std::vector 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,