diff --git a/plugins/plugin_bridge.cpp b/plugins/plugin_bridge.cpp index 2009fdf..9d5675e 100644 --- a/plugins/plugin_bridge.cpp +++ b/plugins/plugin_bridge.cpp @@ -31,7 +31,7 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) } try { - auto* cr = PLUG_RESOLVE_INSTANCE_VERSIONED(Contact3Registry, "1"); + auto* cs = PLUG_RESOLVE_INSTANCE(ContactStore4I); auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModelI); auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI); @@ -40,7 +40,7 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) // static store, could be anywhere tho // construct with fetched dependencies - g_bridge = std::make_unique(*cr, *rmm, *conf, mcd); + g_bridge = std::make_unique(*cs, *rmm, *conf, mcd); // register types PLUG_PROVIDE_INSTANCE(Bridge, plugin_name, g_bridge.get()); diff --git a/src/bridge.cpp b/src/bridge.cpp index a13d7af..5797836 100644 --- a/src/bridge.cpp +++ b/src/bridge.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -10,11 +11,11 @@ #include Bridge::Bridge( - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm, ConfigModelI& conf, MessageCommandDispatcher* mcd -) : _cr(cr), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _conf(conf), _mcd(mcd) { +) : _cs(cs), _rmm(rmm), _rmm_sr(_rmm.newSubRef(this)), _conf(conf), _mcd(mcd) { _rmm_sr.subscribe(RegistryMessageModel_Event::message_construct); if (!_conf.has_bool("Bridge", "username_angle_brackets")) { @@ -38,7 +39,8 @@ Bridge::Bridge( auto& v_group = _vgroups.at(tmp_name_to_id.at(tmp_vgroup_str)); auto& new_vgc = v_group.contacts.emplace_back(); - new_vgc.c = {_cr, entt::null}; // this is annoying af + //new_vgc.c = {}; // TODO: does this work here? + new_vgc.c = _cs.contactHandle(entt::null); new_vgc.id = hex2bin(contact_id); } @@ -67,10 +69,10 @@ void Bridge::updateVGroups(void) { if (!vgc.c.valid()) { // search - auto view = _cr.view(); + auto view = _cs.registry().view(); for (const auto c : view) { if (view.get(c).data == vgc.id) { - vgc.c = {_cr, c}; + vgc.c = _cs.contactHandle(c); std::cout << "Bridge: found contact for vgroup\n"; break; } @@ -96,7 +98,7 @@ void Bridge::registerCommands(void) { const auto contact_from = m.get().c; const auto contact_to = m.get().c; - Contact3Handle group_contact; + ContactHandle4 group_contact; const VirtualGroups* vg = nullptr; if (!params.empty()) { // vgroup_name supplied @@ -114,12 +116,12 @@ void Bridge::registerCommands(void) { return true; } } else { - if (/*is public ?*/ _c_to_vg.count({_cr, contact_to})) { + if (/*is public ?*/ _c_to_vg.count(_cs.contactHandle(contact_to))) { // message was sent public in group - group_contact = {_cr, contact_to}; - } else if (_cr.all_of(contact_from)) { + group_contact = _cs.contactHandle(contact_to); + } else if (_cs.registry().all_of(contact_from)) { // use parent of sender - group_contact = {_cr, _cr.get(contact_from).parent}; + group_contact = _cs.contactHandle(_cs.registry().get(contact_from).parent); } else if (false /* parent of contact_to ? */) { } @@ -156,10 +158,12 @@ void Bridge::registerCommands(void) { "' id:" + bin2hex(vgc.id) ); + const auto& cr = _cs.registry(); + // for each sub contact for (const auto& sub_c : vgc.c.get().subs) { if ( - const auto* sub_cs = _cr.try_get(sub_c); + const auto* sub_cs = cr.try_get(sub_c); sub_cs != nullptr && sub_cs->state == Contact::Components::ConnectionState::disconnected ) { // skip offline @@ -169,9 +173,9 @@ void Bridge::registerCommands(void) { _rmm.sendText( contact_from, " '" + - (_cr.all_of(sub_c) ? _cr.get(sub_c).name : "") + + (cr.all_of(sub_c) ? cr.get(sub_c).name : "") + "'" + - (_cr.all_of(sub_c) ? " id:" + bin2hex(_cr.get(sub_c).data) : "") + (cr.all_of(sub_c) ? " id:" + bin2hex(cr.get(sub_c).data) : "") ); } @@ -193,7 +197,7 @@ void Bridge::registerCommands(void) { std::cout << "Bridge: registered commands\n"; } -const Bridge::VirtualGroups* Bridge::findVGforContact(const Contact3Handle& c) { +const Bridge::VirtualGroups* Bridge::findVGforContact(const ContactHandle4& c) { return nullptr; } @@ -217,14 +221,16 @@ bool Bridge::onEvent(const Message::Events::MessageConstruct& e) { } } + const auto& cr = _cs.registry(); + const auto contact_from = e.e.get().c; - if (_cr.any_of(contact_from)) { + if (cr.any_of(contact_from)) { return false; // skip own messages } const auto contact_to = e.e.get().c; // if e.e is in c to vg - const auto it = _c_to_vg.find(Contact3Handle{_cr, contact_to}); + const auto it = _c_to_vg.find(_cs.contactHandle(contact_to)); if (it == _c_to_vg.cend()) { return false; // contact is not bridged } @@ -239,8 +245,8 @@ bool Bridge::onEvent(const Message::Events::MessageConstruct& e) { from_str += "<"; } - if (_cr.all_of(contact_from)) { - const auto& name = _cr.get(contact_from).name; + if (cr.all_of(contact_from)) { + const auto& name = cr.get(contact_from).name; if (name.empty()) { from_str += "UNK"; } else { @@ -249,9 +255,9 @@ bool Bridge::onEvent(const Message::Events::MessageConstruct& e) { } if (_conf.get_bool("Bridge", "username_id", vgroup.vg_name).value()) { - if (_cr.all_of(contact_from)) { + if (cr.all_of(contact_from)) { // copy - auto id = _cr.get(contact_from).data; + auto id = cr.get(contact_from).data; id.resize(3); // TODO:make size configurable // TODO: make seperator configurable diff --git a/src/bridge.hpp b/src/bridge.hpp index e8b6464..d029de8 100644 --- a/src/bridge.hpp +++ b/src/bridge.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -13,7 +13,7 @@ struct ConfigModelI; class MessageCommandDispatcher; class Bridge : public RegistryMessageModelEventI { - Contact3Registry& _cr; + ContactStore4I& _cs; RegistryMessageModelI& _rmm; RegistryMessageModelI::SubscriptionReference _rmm_sr; ConfigModelI& _conf; @@ -21,7 +21,7 @@ class Bridge : public RegistryMessageModelEventI { struct VirtualGroups { struct VContact { - Contact3Handle c; // might be null + ContactHandle4 c; // might be null std::vector id; // if contact appears, we check }; std::vector contacts; @@ -30,7 +30,7 @@ class Bridge : public RegistryMessageModelEventI { // TODO: cache settings here? }; std::vector _vgroups; - std::map _c_to_vg; + std::map _c_to_vg; float _iterate_timer {0.f}; @@ -38,7 +38,7 @@ class Bridge : public RegistryMessageModelEventI { static constexpr const char* version {"1"}; Bridge( - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm, ConfigModelI& conf, MessageCommandDispatcher* mcd = nullptr @@ -50,7 +50,7 @@ class Bridge : public RegistryMessageModelEventI { private: void updateVGroups(void); void registerCommands(void); - const VirtualGroups* findVGforContact(const Contact3Handle& c); + const VirtualGroups* findVGforContact(const ContactHandle4& c); protected: // mm bool onEvent(const Message::Events::MessageConstruct& e) override;