diff --git a/src/solanaceae/message3/components.hpp b/src/solanaceae/message3/components.hpp index eae1724..61d56ea 100644 --- a/src/solanaceae/message3/components.hpp +++ b/src/solanaceae/message3/components.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "./message.hpp" @@ -8,6 +8,10 @@ #include +#include +#include +#include + #include #include #include @@ -15,11 +19,11 @@ namespace Message::Components { struct ContactFrom { - Contact3 c{entt::null}; + Contact4 c{entt::null}; }; struct ContactTo { - Contact3 c{entt::null}; + Contact4 c{entt::null}; }; // best guess as to how this should be displayed in the global order @@ -48,18 +52,18 @@ namespace Message::Components { struct ReceivedBy { // Due to a lack of info with some protocols, // this is often the timestamp we heard they already have the message. - entt::dense_map ts; + entt::dense_map ts; }; struct ReadBy { - entt::dense_map ts; + entt::dense_map ts; }; // similar to ReceivedBy, but only set when they sent the message // (efficent protocols have 1 contact in here) struct SyncedBy { // ts is not updated once set - entt::dense_map ts; + entt::dense_map ts; }; struct MessageText { diff --git a/src/solanaceae/message3/message_command_dispatcher.cpp b/src/solanaceae/message3/message_command_dispatcher.cpp index 7cfe3ad..09f0ab0 100644 --- a/src/solanaceae/message3/message_command_dispatcher.cpp +++ b/src/solanaceae/message3/message_command_dispatcher.cpp @@ -5,8 +5,8 @@ #include #include #include +#include -#include #include #include #include @@ -14,11 +14,11 @@ #include MessageCommandDispatcher::MessageCommandDispatcher( - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm, ConfigModelI& conf ) : - _cr(cr), _rmm(rmm), _conf(conf), _program_started_at(getTimeMS()) + _cs(cs), _rmm(rmm), _conf(conf), _program_started_at(getTimeMS()) { // overwrite default admin and moderator to false _conf.set("MessageCommandDispatcher", "admin", false); @@ -177,13 +177,14 @@ bool MessageCommandDispatcher::helpCommand(std::string_view params, Message3Hand return true; } -bool MessageCommandDispatcher::hasPermission(const Command& cmd, const Contact3 contact) { - if (!_cr.all_of(contact)) { +bool MessageCommandDispatcher::hasPermission(const Command& cmd, const Contact4 contact) { + const auto& reg = _cs.registry(); + if (!reg.all_of(contact)) { std::cerr << "MCD error: contact without ID\n"; return false; // default to false } - const auto id_str = bin2hex(_cr.get(contact).data); + const auto id_str = bin2hex(reg.get(contact).data); std::cout << "MCD: perm check for id '" << id_str << "'\n"; // TODO: blacklist here @@ -253,14 +254,16 @@ bool MessageCommandDispatcher::onEvent(const Message::Events::MessageConstruct& return false; } + const auto& reg = _cs.registry(); + // skip unrelyable synced if (e.e.all_of()) { const auto& list = e.e.get().ts; if ( std::find_if( list.cbegin(), list.cend(), - [this](const auto&& it) { - return _cr.any_of< + [this, ®](const auto&& it) { + return reg.any_of< Contact::Components::TagSelfStrong, Contact::Components::TagSelfWeak // trust weak self >(it.first); @@ -273,7 +276,7 @@ bool MessageCommandDispatcher::onEvent(const Message::Events::MessageConstruct& } } - const bool is_private = _cr.any_of(e.e.get().c); + const bool is_private = reg.any_of(e.e.get().c); if (is_private) { // check for command prefix diff --git a/src/solanaceae/message3/message_command_dispatcher.hpp b/src/solanaceae/message3/message_command_dispatcher.hpp index ff3fe97..fcbedbc 100644 --- a/src/solanaceae/message3/message_command_dispatcher.hpp +++ b/src/solanaceae/message3/message_command_dispatcher.hpp @@ -1,7 +1,7 @@ #pragma once +#include #include -#include #include #include @@ -13,7 +13,7 @@ struct ConfigModelI; class MessageCommandDispatcher : public RegistryMessageModelEventI { - Contact3Registry& _cr; + ContactStore4I& _cs; RegistryMessageModelI& _rmm; ConfigModelI& _conf; @@ -48,7 +48,7 @@ class MessageCommandDispatcher : public RegistryMessageModelEventI { std::unordered_map _command_map; struct QueuedMessage { - Contact3 to; + Contact4 to; std::string message; }; std::deque _message_queue; @@ -56,7 +56,7 @@ class MessageCommandDispatcher : public RegistryMessageModelEventI { uint64_t _program_started_at {0}; public: - MessageCommandDispatcher(Contact3Registry& cr, RegistryMessageModelI& rmm, ConfigModelI& conf); + MessageCommandDispatcher(ContactStore4I& cs, RegistryMessageModelI& rmm, ConfigModelI& conf); ~MessageCommandDispatcher(void); float iterate(float time_delta); @@ -78,7 +78,7 @@ class MessageCommandDispatcher : public RegistryMessageModelEventI { // generates a help bool helpCommand(std::string_view params, Message3Handle m); - bool hasPermission(const Command& cmd, const Contact3 contact); + bool hasPermission(const Command& cmd, const Contact4 contact); protected: // mm bool onEvent(const Message::Events::MessageConstruct& e) override; diff --git a/src/solanaceae/message3/message_model3.hpp b/src/solanaceae/message3/message_model3.hpp index 7442714..597fe91 100644 --- a/src/solanaceae/message3/message_model3.hpp +++ b/src/solanaceae/message3/message_model3.hpp @@ -1,8 +1,11 @@ #pragma once -#include +#include #include +#include +#include + // TODO: move, rename, do something?, change in favor of tox? //enum class FileKind : uint32_t { //file = 0u, @@ -15,11 +18,11 @@ struct MessageModel3I { // return true if a handler was found for the contact - virtual bool sendText(const Contact3 c, std::string_view message, bool action = false) { (void)c,(void)message,(void)action; return false; } + virtual bool sendText(const Contact4 c, std::string_view message, bool action = false) { (void)c,(void)message,(void)action; return false; } //virtual bool sendFile(const Contact& c, std::string_view file_name, std::unique_ptr file) { (void)c,(void)message,(void)action; return false; } - virtual bool sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) { (void)c,(void)file_name,(void)file_path; return false; } - virtual bool sendFileObj(const Contact3 c, ObjectHandle o) { (void)c,(void)o; return false; } // ideal for forwarding + virtual bool sendFilePath(const Contact4 c, std::string_view file_name, std::string_view file_path) { (void)c,(void)file_name,(void)file_path; return false; } + virtual bool sendFileObj(const Contact4 c, ObjectHandle o) { (void)c,(void)o; return false; } // ideal for forwarding // we want this back :) //virtual bool sendFileMem(const Contact& c, std::string_view file_name, const std::vector& file) = 0; diff --git a/src/solanaceae/message3/registry_message_model.hpp b/src/solanaceae/message3/registry_message_model.hpp index 602d3e5..881fdee 100644 --- a/src/solanaceae/message3/registry_message_model.hpp +++ b/src/solanaceae/message3/registry_message_model.hpp @@ -64,12 +64,12 @@ using RegistryMessageModelEventProviderI = EventProviderI diff --git a/src/solanaceae/message3/registry_message_model_impl.cpp b/src/solanaceae/message3/registry_message_model_impl.cpp index 9b0295b..5af59ad 100644 --- a/src/solanaceae/message3/registry_message_model_impl.cpp +++ b/src/solanaceae/message3/registry_message_model_impl.cpp @@ -1,19 +1,21 @@ #include "./registry_message_model_impl.hpp" #include +#include #include -Message3Registry* RegistryMessageModelImpl::get(Contact3 c) { - if (_cr.valid(c) && !_cr.all_of(c)) { +Message3Registry* RegistryMessageModelImpl::get(Contact4 c) { + const auto& reg = _cs.registry(); + if (reg.valid(c) && !reg.all_of(c)) { // TODO: loop upwards - if (!_cr.all_of(c)) { + if (!reg.all_of(c)) { return nullptr; } - c = _cr.get(c).parent; + c = reg.get(c).parent; } - if (!_cr.valid(c)) { + if (!reg.valid(c)) { // TODO: throw error return nullptr; } @@ -24,20 +26,21 @@ Message3Registry* RegistryMessageModelImpl::get(Contact3 c) { } auto& reg_sh = _contact_messages[c] = std::make_unique(); - reg_sh->ctx().emplace(c); + reg_sh->ctx().emplace(c); return reg_sh.get(); } -Message3Registry* RegistryMessageModelImpl::get(Contact3 c) const { - if (_cr.valid(c) && !_cr.all_of(c)) { +Message3Registry* RegistryMessageModelImpl::get(Contact4 c) const { + const auto& reg = _cs.registry(); + if (reg.valid(c) && !reg.all_of(c)) { // TODO: loop upwards - if (!_cr.all_of(c)) { + if (!reg.all_of(c)) { return nullptr; } - c = _cr.get(c).parent; + c = reg.get(c).parent; } - if (!_cr.valid(c)) { + if (!reg.valid(c)) { // TODO: throw error return nullptr; } @@ -90,25 +93,25 @@ void RegistryMessageModelImpl::throwEventDestroy(Message3Registry& reg, Message3 ); } -void RegistryMessageModelImpl::throwEventConstruct(const Contact3 c, Message3 e) { +void RegistryMessageModelImpl::throwEventConstruct(const Contact4 c, Message3 e) { if (auto* reg_ptr = get(c); reg_ptr) { throwEventConstruct(*reg_ptr, e); } } -void RegistryMessageModelImpl::throwEventUpdate(const Contact3 c, Message3 e) { +void RegistryMessageModelImpl::throwEventUpdate(const Contact4 c, Message3 e) { if (auto* reg_ptr = get(c); reg_ptr) { throwEventUpdate(*reg_ptr, e); } } -void RegistryMessageModelImpl::throwEventDestroy(const Contact3 c, Message3 e) { +void RegistryMessageModelImpl::throwEventDestroy(const Contact4 c, Message3 e) { if (auto* reg_ptr = get(c); reg_ptr) { throwEventDestroy(*reg_ptr, e); } } -bool RegistryMessageModelImpl::sendText(const Contact3 c, std::string_view message, bool action) { +bool RegistryMessageModelImpl::sendText(const Contact4 c, std::string_view message, bool action) { std::cout << "RMM debug: event send text\n"; // manual, bc its not an "event" @@ -123,7 +126,7 @@ bool RegistryMessageModelImpl::sendText(const Contact3 c, std::string_view messa return false; } -bool RegistryMessageModelImpl::sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) { +bool RegistryMessageModelImpl::sendFilePath(const Contact4 c, std::string_view file_name, std::string_view file_path) { std::cout << "RMM debug: event send file path\n"; // manual, bc its not an "event" diff --git a/src/solanaceae/message3/registry_message_model_impl.hpp b/src/solanaceae/message3/registry_message_model_impl.hpp index 5eeb17b..5cfa637 100644 --- a/src/solanaceae/message3/registry_message_model_impl.hpp +++ b/src/solanaceae/message3/registry_message_model_impl.hpp @@ -2,30 +2,28 @@ #include "./registry_message_model.hpp" -#include -#include #include #include class RegistryMessageModelImpl : public RegistryMessageModelI { protected: - Contact3Registry& _cr; + ContactStore4I& _cs; - entt::dense_map> _contact_messages; + entt::dense_map> _contact_messages; bool _update_in_progess {false}; std::vector _update_queue {}; public: - RegistryMessageModelImpl(Contact3Registry& cr) : _cr(cr) {} + RegistryMessageModelImpl(ContactStore4I& cs) : _cs(cs) {} virtual ~RegistryMessageModelImpl(void) {} // TODO: iterate? public: - Message3Registry* get(Contact3 c) override; - Message3Registry* get(Contact3 c) const override; + Message3Registry* get(Contact4 c) override; + Message3Registry* get(Contact4 c) const override; public: // dispatcher // !!! remember to manually throw these externally @@ -33,12 +31,12 @@ class RegistryMessageModelImpl : public RegistryMessageModelI { void throwEventUpdate(Message3Registry& reg, Message3 e) override; void throwEventDestroy(Message3Registry& reg, Message3 e) override; - void throwEventConstruct(const Contact3 c, Message3 e) override; - void throwEventUpdate(const Contact3 c, Message3 e) override; - void throwEventDestroy(const Contact3 c, Message3 e) override; + void throwEventConstruct(const Contact4 c, Message3 e) override; + void throwEventUpdate(const Contact4 c, Message3 e) override; + void throwEventDestroy(const Contact4 c, Message3 e) override; public: // mm3 - bool sendText(const Contact3 c, std::string_view message, bool action = false) override; - bool sendFilePath(const Contact3 c, std::string_view file_name, std::string_view file_path) override; + bool sendText(const Contact4 c, std::string_view message, bool action = false) override; + bool sendFilePath(const Contact4 c, std::string_view file_name, std::string_view file_path) override; };