Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3274986
D3940.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
16 KB
Referenced Files
None
Subscribers
None
D3940.diff
View Options
diff --git a/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs.h
new file mode 100644
--- /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 <map>
+
+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<MessageType, std::unique_ptr<MessageSpec>> messageSpecsHolder =
+ []() {
+ std::map<MessageType, std::unique_ptr<MessageSpec>>
+ 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/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/ChangeRoleMessageSpec.h b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/ChangeRoleMessageSpec.h
new file mode 100644
--- /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<std::string>
+ messageContentForClientDB(const folly::dynamic &rawMessageInfo) override {
+ folly::dynamic changeRoleData =
+ folly::dynamic::object("userIDs", rawMessageInfo["userIDs"])(
+ "newRole", rawMessageInfo["newRole"]);
+ return std::make_unique<std::string>(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
--- /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<std::string>
+ messageContentForClientDB(const folly::dynamic &rawMessageInfo) override {
+ folly::dynamic changeSettingsData = folly::dynamic::object(
+ rawMessageInfo["field"].asString(), rawMessageInfo["value"]);
+ return std::make_unique<std::string>(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
--- /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<std::string>
+ 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<std::string>(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
--- /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<std::string>
+ messageContentForClientDB(const folly::dynamic &rawMessageInfo) override {
+ folly::dynamic createSidebarData = rawMessageInfo["initialThreadState"];
+ createSidebarData["sourceMessageAuthorID"] =
+ rawMessageInfo["sourceMessageAuthorID"];
+ return std::make_unique<std::string>(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
--- /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<std::string>
+ messageContentForClientDB(const folly::dynamic &rawMessageInfo) override {
+ return std::make_unique<std::string>(
+ 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
--- /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<std::string>
+ messageContentForClientDB(const folly::dynamic &rawMessageInfo) override {
+ folly::dynamic initialThreadState = rawMessageInfo["initialThreadState"];
+ return std::make_unique<std::string>(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
--- /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<std::string>
+ 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<std::string>(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
--- /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<std::string>
+ 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<std::string>(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
--- /dev/null
+++ b/native/cpp/CommonCpp/NativeModules/PersistentStorageUtilities/MessageOperationsUtilities/MessageSpecs/MessageSpec.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <folly/String.h>
+#include <folly/dynamic.h>
+#include <folly/json.h>
+#include <string>
+#include <vector>
+
+namespace comm {
+class MessageSpec {
+public:
+ virtual std::unique_ptr<std::string>
+ 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
--- /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<std::string>
+ 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<std::string>(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
--- /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<std::string>
+ 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<std::string>(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
--- /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<std::string>
+ messageContentForClientDB(const folly::dynamic &rawMessageInfo) override {
+ return std::make_unique<std::string>(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
--- /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<std::string>
+ 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<std::string>(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
--- /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<std::string>
+ messageContentForClientDB(const folly::dynamic &rawMessageInfo) override {
+ folly::dynamic updateRelationshipData =
+ folly::dynamic::object("operation", rawMessageInfo["operation"])(
+ "targetID", rawMessageInfo["targetID"]);
+ return std::make_unique<std::string>(folly::toJson(updateRelationshipData));
+ }
+};
+} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 6:51 AM (21 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2516897
Default Alt Text
D3940.diff (16 KB)
Attached To
Mode
D3940: Define message spec interface and implement it for each message type that produces notifications
Attached
Detach File
Event Timeline
Log In to Comment