diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs.h new file mode 100644 index 000000000..afa6e830e --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs.h @@ -0,0 +1,89 @@ +#pragma once + +#include "MessageSpecs/ChangeRoleMessageSpec.h" +#include "MessageSpecs/ChangeSettingsMessageSpec.h" +#include "MessageSpecs/CreateEntryMessageSpec.h" +#include "MessageSpecs/CreateSidebarMessageSpec.h" +#include "MessageSpecs/CreateSubThreadMessageSpec.h" +#include "MessageSpecs/CreateThreadMessageSpec.h" +#include "MessageSpecs/DeleteEntryMessageSpec.h" +#include "MessageSpecs/EditEntryMessageSpec.h" +#include "MessageSpecs/MessageSpec.h" +#include "MessageSpecs/MultimediaMessageSpec.h" +#include "MessageSpecs/RestoreEntryMessageSpec.h" +#include "MessageSpecs/TextMessageSpec.h" +#include "MessageSpecs/UnsupportedMessageSpec.h" +#include "MessageSpecs/UpdateRelationshipMessageSpec.h" + +#include + +namespace comm { + +enum class MessageType { + TEXT, + CREATE_THREAD, + ADD_MEMBERS, + CREATE_SUB_THREAD, + CHANGE_SETTINGS, + REMOVE_MEMBERS, + CHANGE_ROLE, + LEAVE_THREAD, + JOIN_THREAD, + CREATE_ENTRY, + EDIT_ENTRY, + DELETE_ENTRY, + RESTORE_ENTRY, + UNSUPPORTED, + IMAGES, + MULTIMEDIA, + UPDATE_RELATIONSHIP, + SIDEBAR_SOURCE, + CREATE_SIDEBAR, +}; + +const std::map> messageSpecsHolder = + []() { + std::map> + message_specs_initializer; + message_specs_initializer.insert( + {MessageType::TEXT, std::make_unique()}); + message_specs_initializer.insert( + {MessageType::CREATE_THREAD, + std::make_unique()}); + message_specs_initializer.insert( + {MessageType::CREATE_SUB_THREAD, + std::make_unique()}); + message_specs_initializer.insert( + {MessageType::CHANGE_SETTINGS, + std::make_unique()}); + message_specs_initializer.insert( + {MessageType::CHANGE_ROLE, + std::make_unique()}); + message_specs_initializer.insert( + {MessageType::CREATE_ENTRY, + std::make_unique()}); + message_specs_initializer.insert( + {MessageType::EDIT_ENTRY, std::make_unique()}); + message_specs_initializer.insert( + {MessageType::DELETE_ENTRY, + std::make_unique()}); + message_specs_initializer.insert( + {MessageType::RESTORE_ENTRY, + std::make_unique()}); + message_specs_initializer.insert( + {MessageType::UNSUPPORTED, + std::make_unique()}); + message_specs_initializer.insert( + {MessageType::IMAGES, std::make_unique()}); + message_specs_initializer.insert( + {MessageType::MULTIMEDIA, std::make_unique()}); + message_specs_initializer.insert( + {MessageType::UPDATE_RELATIONSHIP, + std::make_unique()}); + message_specs_initializer.insert( + {MessageType::CREATE_SIDEBAR, + std::make_unique()}); + return message_specs_initializer; + }(); + +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/ChangeRoleMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/ChangeRoleMessageSpec.h new file mode 100644 index 000000000..83f853466 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/ChangeRoleMessageSpec.h @@ -0,0 +1,15 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class ChangeRoleMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic changeRoleData = + folly::dynamic::object("userIDs", rawMessageInfo["userIDs"])( + "newRole", rawMessageInfo["newRole"]); + return std::make_unique(folly::toJson(changeRoleData)); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/ChangeSettingsMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/ChangeSettingsMessageSpec.h new file mode 100644 index 000000000..ce401db8c --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/ChangeSettingsMessageSpec.h @@ -0,0 +1,14 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class ChangeSettingsMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic changeSettingsData = folly::dynamic::object( + rawMessageInfo["field"].asString(), rawMessageInfo["value"]); + return std::make_unique(folly::toJson(changeSettingsData)); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateEntryMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateEntryMessageSpec.h new file mode 100644 index 000000000..ba3cd6f96 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateEntryMessageSpec.h @@ -0,0 +1,15 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class CreateEntryMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic entryData = + folly::dynamic::object("entryID", rawMessageInfo["entryID"])( + "date", rawMessageInfo["date"])("text", rawMessageInfo["text"]); + return std::make_unique(folly::toJson(entryData)); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateSidebarMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateSidebarMessageSpec.h new file mode 100644 index 000000000..f6b8dd8a1 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateSidebarMessageSpec.h @@ -0,0 +1,15 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class CreateSidebarMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic createSidebarData = rawMessageInfo["initialThreadState"]; + createSidebarData["sourceMessageAuthorID"] = + rawMessageInfo["sourceMessageAuthorID"]; + return std::make_unique(folly::toJson(createSidebarData)); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateSubThreadMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateSubThreadMessageSpec.h new file mode 100644 index 000000000..0e8ed98ff --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateSubThreadMessageSpec.h @@ -0,0 +1,13 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class CreateSubThreadMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + return std::make_unique( + rawMessageInfo["childThreadID"].asString()); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateThreadMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateThreadMessageSpec.h new file mode 100644 index 000000000..4143cd076 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/CreateThreadMessageSpec.h @@ -0,0 +1,13 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class CreateThreadMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic initialThreadState = rawMessageInfo["initialThreadState"]; + return std::make_unique(folly::toJson(initialThreadState)); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/DeleteEntryMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/DeleteEntryMessageSpec.h new file mode 100644 index 000000000..e258c175a --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/DeleteEntryMessageSpec.h @@ -0,0 +1,15 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class DeleteEntryMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic entryData = + folly::dynamic::object("entryID", rawMessageInfo["entryID"])( + "date", rawMessageInfo["date"])("text", rawMessageInfo["text"]); + return std::make_unique(folly::toJson(entryData)); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/EditEntryMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/EditEntryMessageSpec.h new file mode 100644 index 000000000..6665b8dc2 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/EditEntryMessageSpec.h @@ -0,0 +1,15 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class EditEntryMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic entryData = + folly::dynamic::object("entryID", rawMessageInfo["entryID"])( + "date", rawMessageInfo["date"])("text", rawMessageInfo["text"]); + return std::make_unique(folly::toJson(entryData)); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/MessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/MessageSpec.h new file mode 100644 index 000000000..5b672900f --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/MessageSpec.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace comm { +class MessageSpec { +public: + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) = 0; +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/MultimediaMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/MultimediaMessageSpec.h new file mode 100644 index 000000000..c9faf9091 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/MultimediaMessageSpec.h @@ -0,0 +1,16 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class MultimediaMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic mediaIDs = folly::dynamic::array(); + for (const auto &mediaInfo : rawMessageInfo["media"]) { + mediaIDs.push_back(std::stoi(mediaInfo["id"].asString())); + } + return std::make_unique(folly::toJson(mediaIDs)); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/RestoreEntryMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/RestoreEntryMessageSpec.h new file mode 100644 index 000000000..004155bc6 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/RestoreEntryMessageSpec.h @@ -0,0 +1,15 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class RestoreEntryMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic entryData = + folly::dynamic::object("entryID", rawMessageInfo["entryID"])( + "date", rawMessageInfo["date"])("text", rawMessageInfo["text"]); + return std::make_unique(folly::toJson(entryData)); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/TextMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/TextMessageSpec.h new file mode 100644 index 000000000..d86c7280a --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/TextMessageSpec.h @@ -0,0 +1,12 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class TextMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + return std::make_unique(rawMessageInfo["text"].asString()); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/UnsupportedMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/UnsupportedMessageSpec.h new file mode 100644 index 000000000..f67524742 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/UnsupportedMessageSpec.h @@ -0,0 +1,16 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class UnsupportedMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic unsupportedMessageData = + folly::dynamic::object("robotext", rawMessageInfo["robotext"])( + "dontPrefixCreator", rawMessageInfo["dontPrefixCreator"])( + "unsupportedMessageInfo", rawMessageInfo["unsupportedMessageInfo"]); + return std::make_unique(folly::toJson(unsupportedMessageData)); + } +}; +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/UpdateRelationshipMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/UpdateRelationshipMessageSpec.h new file mode 100644 index 000000000..2c15b1ce4 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/UpdateRelationshipMessageSpec.h @@ -0,0 +1,15 @@ +#pragma once + +#include "MessageSpec.h" + +namespace comm { +class UpdateRelationshipMessageSpec : public MessageSpec { + virtual std::unique_ptr + messageContentForClientDB(const folly::dynamic &rawMessageInfo) override { + folly::dynamic updateRelationshipData = + folly::dynamic::object("operation", rawMessageInfo["operation"])( + "targetID", rawMessageInfo["targetID"]); + return std::make_unique(folly::toJson(updateRelationshipData)); + } +}; +} // namespace comm