diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index af0da59..b297c58 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -33,6 +33,7 @@ target_compile_features(totato PUBLIC cxx_std_17) target_link_libraries(totato PUBLIC solanaceae_util solanaceae_contact + solanaceae_contact_impl solanaceae_message3 solanaceae_plugin diff --git a/src/config_commands.cpp b/src/config_commands.cpp index 0baec0a..744510a 100644 --- a/src/config_commands.cpp +++ b/src/config_commands.cpp @@ -1,6 +1,6 @@ #include "./managment_commands.hpp" -#include +#include #include #include @@ -13,7 +13,7 @@ void registerConfigCommands( MessageCommandDispatcher& mcd, ConfigModelI& conf, - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm ) { mcd.registerCommand( diff --git a/src/config_commands.hpp b/src/config_commands.hpp index 45260a5..1e2f6e1 100644 --- a/src/config_commands.hpp +++ b/src/config_commands.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include // fwd @@ -10,7 +10,7 @@ struct ConfigModelI; void registerConfigCommands( MessageCommandDispatcher& mcd, ConfigModelI& conf, - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm ); diff --git a/src/fun_commands.cpp b/src/fun_commands.cpp index a3786a1..1379811 100644 --- a/src/fun_commands.cpp +++ b/src/fun_commands.cpp @@ -1,18 +1,19 @@ #include "./managment_commands.hpp" -#include -#include //#include +#include #include -#include //#include +#include + +#include void registerFunCommands( MessageCommandDispatcher& mcd, ConfigModelI& conf, - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm ) { mcd.registerCommand( diff --git a/src/fun_commands.hpp b/src/fun_commands.hpp index 81c159a..bbccbb2 100644 --- a/src/fun_commands.hpp +++ b/src/fun_commands.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include // fwd @@ -10,7 +9,7 @@ struct ConfigModelI; void registerFunCommands( MessageCommandDispatcher& mcd, ConfigModelI& conf, - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm ); diff --git a/src/main.cpp b/src/main.cpp index ea78c68..dc036b1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -185,11 +185,11 @@ int main(int argc, char** argv) { // TODO: name } - Contact3Registry cr; - RegistryMessageModelImpl rmm{cr}; + ContactStore4Impl cs; + RegistryMessageModelImpl rmm{cs}; MessageTimeSort mts{rmm}; - MessageCleanser mc{cr, rmm, conf}; - MessageCommandDispatcher mcd{cr, rmm, conf}; + MessageCleanser mc{cs, rmm, conf}; + MessageCommandDispatcher mcd{cs, rmm, conf}; { // setup basic commands for bot mcd.registerCommand( @@ -223,9 +223,9 @@ int main(int argc, char** argv) { ToxPrivateImpl tpi{tc.getTox()}; AutoDirty ad{tc}; - ToxContactModel2 tcm{cr, tc, tc}; - ToxMessageManager tmm{rmm, cr, tcm, tc, tc}; - ToxTransferManager ttm{rmm, cr, tcm, tc, tc, os}; + ToxContactModel2 tcm{cs, tc, tc}; + ToxMessageManager tmm{rmm, cs, tcm, tc, tc}; + ToxTransferManager ttm{rmm, cs, tcm, tc, tc, os}; PluginManager pm; @@ -233,7 +233,7 @@ int main(int argc, char** argv) { g_provideInstance("ObjectStore2", "host", &os); g_provideInstance("ConfigModelI", "host", &conf); - g_provideInstance("Contact3Registry", "1", "host", &cr); + g_provideInstance("ContactStore4I", "host", &cs); g_provideInstance("RegistryMessageModelI", "host", &rmm); g_provideInstance("MessageCommandDispatcher", "host", &mcd); @@ -267,11 +267,11 @@ int main(int argc, char** argv) { } } - registerManagementCommands(mcd, conf, cr, rmm); + registerManagementCommands(mcd, conf, cs, rmm); // TODO: finish impl - //registerConfigCommands(mcd, conf, cr, rmm); - registerToxCommands(mcd, conf, cr, rmm, tc, tpi); - registerFunCommands(mcd, conf, cr, rmm); + //registerConfigCommands(mcd, conf, cs, rmm); + registerToxCommands(mcd, conf, cs, rmm, tc, tpi); + registerFunCommands(mcd, conf, cs, rmm); mcd.registerCommand( "totato", "", diff --git a/src/managment_commands.cpp b/src/managment_commands.cpp index 9a51a12..b3982e8 100644 --- a/src/managment_commands.cpp +++ b/src/managment_commands.cpp @@ -1,6 +1,6 @@ #include "./managment_commands.hpp" -#include +#include #include #include @@ -12,25 +12,22 @@ #include #include -static std::optional getContactFromIDStr( - Contact3Registry& cr, +static std::optional getContactFromIDStr( + ContactStore4I& cs, std::string_view id_str ) { - const std::vector id = hex2bin(std::string{id_str}); - const auto view = cr.view(); - const auto found_contact = std::find_if(view.begin(), view.end(), [&id, &view](const Contact3 c) -> bool { - return view.get(c).data == id; - }); + const std::vector id = hex2bin(id_str); + const auto found_contact = cs.getOneContactByID(ByteSpan{id}); - if (found_contact != view.end()) { - return *found_contact; + if (static_cast(found_contact)) { + return found_contact; } else { return std::nullopt; } } static std::string getStatusFromContact( - Contact3Handle c + ContactHandle4 c ) { std::string status_str; @@ -53,7 +50,7 @@ static std::string getStatusFromContact( bool handleContactAddToGroup( ConfigModelI& conf, - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm, std::string_view params, @@ -73,7 +70,7 @@ bool handleContactAddToGroup( return true; } - const auto target_opt = getContactFromIDStr(cr, params); + const auto target_opt = getContactFromIDStr(cs, params); if (!target_opt.has_value()) { rmm.sendText( contact_from, @@ -99,7 +96,7 @@ bool handleContactAddToGroup( reply += "' to the "; reply += group; reply += "s.\n"; - reply += getStatusFromContact(Contact3Handle{cr, target_opt.value()}); + reply += getStatusFromContact(cs.contactHandle(target_opt.value())); rmm.sendText( contact_from, @@ -112,14 +109,14 @@ bool handleContactAddToGroup( void registerManagementCommands( MessageCommandDispatcher& mcd, ConfigModelI& conf, - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm ) { mcd.registerCommand( "Management", "manage", "admin-add", [&](std::string_view params, Message3Handle m) -> bool { - return handleContactAddToGroup(conf, cr, rmm, params, m, "admin"); + return handleContactAddToGroup(conf, cs, rmm, params, m, "admin"); }, "Add an admin by ID.", MessageCommandDispatcher::Perms::ADMIN @@ -129,7 +126,7 @@ void registerManagementCommands( "Management", "manage", "mod-add", [&](std::string_view params, Message3Handle m) -> bool { - return handleContactAddToGroup(conf, cr, rmm, params, m, "moderator"); + return handleContactAddToGroup(conf, cs, rmm, params, m, "moderator"); }, "Add a moderator by ID.", MessageCommandDispatcher::Perms::ADMIN diff --git a/src/managment_commands.hpp b/src/managment_commands.hpp index 08841cb..6efd7d5 100644 --- a/src/managment_commands.hpp +++ b/src/managment_commands.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include // fwd @@ -10,7 +10,7 @@ struct ConfigModelI; void registerManagementCommands( MessageCommandDispatcher& mcd, ConfigModelI& conf, - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm ); diff --git a/src/message_cleanser.cpp b/src/message_cleanser.cpp index 5ccc42e..24a9ef5 100644 --- a/src/message_cleanser.cpp +++ b/src/message_cleanser.cpp @@ -1,5 +1,6 @@ #include "./message_cleanser.hpp" +#include #include #include #include @@ -9,10 +10,10 @@ #include MessageCleanser::MessageCleanser( - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm, ConfigModelI& conf -) : _cr(cr), _rmm(rmm), _conf(conf) { +) : _cs(cs), _rmm(rmm), _conf(conf) { if (!_conf.has_int("MessageCleanser", "old_age_minutes")) { _conf.set("MessageCleanser", "old_age_minutes", int64_t(_old_age_default)); } @@ -30,15 +31,17 @@ float MessageCleanser::iterate(float time_delta) { uint64_t now_ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + const auto& cr = _cs.registry(); + // TODO: iterate rmm directly //_rmm.get(); // workaround by iterating contacts - for (const auto& c : _cr.view()) { + for (const auto& c : cr.view()) { if (auto* reg = _rmm.get(c); reg != nullptr) { float old_age {0.f}; { // old age from conf // TODO: find some way to extract this (maybe map into contact reg?) - if (const auto* id_comp = _cr.try_get(c); id_comp != nullptr) { + if (const auto* id_comp = cr.try_get(c); id_comp != nullptr) { const auto id_hex = bin2hex(id_comp->data); old_age = _conf.get_int("MessageCleanser", "old_age_minutes", id_hex).value_or(_old_age_default); } else { diff --git a/src/message_cleanser.hpp b/src/message_cleanser.hpp index 7d222c0..b71c7d7 100644 --- a/src/message_cleanser.hpp +++ b/src/message_cleanser.hpp @@ -4,7 +4,7 @@ #include class MessageCleanser { - Contact3Registry& _cr; + ContactStore4I& _cs; RegistryMessageModelI& _rmm; ConfigModelI& _conf; @@ -15,7 +15,7 @@ class MessageCleanser { public: MessageCleanser( - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm, ConfigModelI& conf ); diff --git a/src/tox_commands.cpp b/src/tox_commands.cpp index 82e690d..2255d0b 100644 --- a/src/tox_commands.cpp +++ b/src/tox_commands.cpp @@ -1,6 +1,6 @@ #include "./tox_commands.hpp" -#include +#include #include #include #include @@ -17,7 +17,7 @@ void registerToxCommands( MessageCommandDispatcher& mcd, ConfigModelI& conf, - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm, ToxI& t, ToxPrivateI& tp @@ -43,6 +43,8 @@ void registerToxCommands( reply += "\ndht-closenum-announce-capable:"; reply += std::to_string(tp.toxDHTGetNumCloselistAnnounceCapable()); + const auto& cr = cs.registry(); + if (cr.all_of(contact_from)) { const auto con_opt = t.toxFriendGetConnectionStatus(cr.get(contact_from).friend_number); if (!con_opt.has_value() || con_opt.value() == Tox_Connection::TOX_CONNECTION_NONE) { @@ -174,6 +176,8 @@ void registerToxCommands( return true; } + const auto& cr = cs.registry(); + // get current group if (!cr.all_of(contact_from)) { rmm.sendText( diff --git a/src/tox_commands.hpp b/src/tox_commands.hpp index 0ed03c3..57e2b85 100644 --- a/src/tox_commands.hpp +++ b/src/tox_commands.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include // fwd @@ -12,7 +12,7 @@ struct ToxPrivateI; void registerToxCommands( MessageCommandDispatcher& mcd, ConfigModelI& conf, - Contact3Registry& cr, + ContactStore4I& cs, RegistryMessageModelI& rmm, ToxI& t, ToxPrivateI& tp