diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs.h @@ -0,0 +1,94 @@ +#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 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> MESSAGE_SPECS = []() { + std::map> message_specs_initializer; + message_specs_initializer.insert( + {MessageType::TEXT, + std::make_unique(TextMessageSpec())}); + message_specs_initializer.insert( + {MessageType::CREATE_THREAD, + std::make_unique(CreateThreadMessageSpec())}); + message_specs_initializer.insert( + {MessageType::CREATE_SUB_THREAD, + std::make_unique( + CreateSubThreadMessageSpec())}); + message_specs_initializer.insert( + {MessageType::CHANGE_SETTINGS, + std::make_unique( + ChangeSettingsMessageSpec())}); + message_specs_initializer.insert( + {MessageType::CHANGE_ROLE, + std::make_unique(ChangeRoleMessageSpec())}); + message_specs_initializer.insert( + {MessageType::CREATE_ENTRY, + std::make_unique(CreateEntryMessageSpec())}); + message_specs_initializer.insert( + {MessageType::EDIT_ENTRY, + std::make_unique(EditEntryMessageSpec())}); + message_specs_initializer.insert( + {MessageType::DELETE_ENTRY, + std::make_unique(DeleteEntryMessageSpec())}); + message_specs_initializer.insert( + {MessageType::RESTORE_ENTRY, + std::make_unique(RestoreEntryMessageSpec())}); + message_specs_initializer.insert( + {MessageType::UNSUPPORTED, + std::make_unique(UnsupportedMessageSpec())}); + message_specs_initializer.insert( + {MessageType::IMAGES, + std::make_unique(MultimediaMessageSpec())}); + message_specs_initializer.insert( + {MessageType::MULTIMEDIA, + std::make_unique(MultimediaMessageSpec())}); + message_specs_initializer.insert( + {MessageType::UPDATE_RELATIONSHIP, + std::make_unique( + UpdateRelationshipMessageSpec())}); + message_specs_initializer.insert( + {MessageType::CREATE_SIDEBAR, + std::make_unique(CreateSidebarMessageSpec())}); + return message_specs_initializer; +}(); + +} // namespace comm diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/ChangeRoleMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/ChangeRoleMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/ChangeSettingsMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/ChangeSettingsMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/CreateEntryMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/CreateEntryMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/CreateSidebarMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/CreateSidebarMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/CreateSubThreadMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/CreateSubThreadMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/CreateThreadMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/CreateThreadMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/DeleteEntryMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/DeleteEntryMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/EditEntryMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/EditEntryMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/MessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/MessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/MultimediaMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/MultimediaMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/RestoreEntryMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/RestoreEntryMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/TextMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/TextMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/UnsupportedMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/UnsupportedMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file diff --git a/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/UpdateRelationshipMessageSpec.h b/native/cpp/CommonCpp/NativeModules/MessageOperationsUtilities/MessageSpecs/UpdateRelationshipMessageSpec.h new file mode 100644 --- /dev/null +++ b/native/cpp/CommonCpp/NativeModules/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 \ No newline at end of file