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 @@ -1,7 +1,10 @@ #include "MessageOperationsUtilities.h" +#include "Logger.h" #include "MessageSpecs.h" #include +#include +#include namespace comm { ClientDBMessageInfo @@ -72,4 +75,36 @@ return Media{id, container, thread, uri, type, extras}; } +std::vector +MessageOperationsUtilities::translateStringToClientDBMessageInfos( + std::string &rawMessageInfoString) { + std::vector clientDBMessageInfos; + folly::dynamic rawMessageInfos; + try { + rawMessageInfos = + folly::parseJson(folly::trimWhitespace(rawMessageInfoString)); + } catch (const folly::json::parse_error &e) { + Logger::log( + "Failed to convert message into JSON object. Details: " + + std::string(e.what())); + return clientDBMessageInfos; + } + for (const auto &messageInfo : rawMessageInfos) { + try { + clientDBMessageInfos.push_back( + translateRawMessageInfoToClientDBMessageInfo(messageInfo)); + } catch (const folly::TypeError &e) { + Logger::log( + "Invalid type conversion when parsing message. Details: " + + std::string(e.what())); + } catch (const std::out_of_range &e) { + Logger::log( + "Non-existing key accessed when parsing message. Details: " + + std::string(e.what())); + } + } + + return clientDBMessageInfos; +} + } // namespace comm