diff --git a/external/solanaceae_message3 b/external/solanaceae_message3 index f1dd510..9728f71 160000 --- a/external/solanaceae_message3 +++ b/external/solanaceae_message3 @@ -1 +1 @@ -Subproject commit f1dd5107f820fe86cb6b6b9ca22d42e0a3a3cf30 +Subproject commit 9728f71c9833baa65995e19e993d3450da750c20 diff --git a/external/solanaceae_ngc_ft1 b/external/solanaceae_ngc_ft1 index 54ace9d..6da1f9a 160000 --- a/external/solanaceae_ngc_ft1 +++ b/external/solanaceae_ngc_ft1 @@ -1 +1 @@ -Subproject commit 54ace9d0b2e98d3b3ff70bd9bc7821b1d150dfdc +Subproject commit 6da1f9afca264cf99d124238e95e49b0ed489284 diff --git a/external/solanaceae_object_store b/external/solanaceae_object_store index 4605d64..2801fc2 160000 --- a/external/solanaceae_object_store +++ b/external/solanaceae_object_store @@ -1 +1 @@ -Subproject commit 4605d64df28c45096cef7748d5c143e942aefeb1 +Subproject commit 2801fc21fbd6f69479f6638ab1725d00238698f8 diff --git a/external/solanaceae_tox b/external/solanaceae_tox index 676e50c..1a3d9dd 160000 --- a/external/solanaceae_tox +++ b/external/solanaceae_tox @@ -1 +1 @@ -Subproject commit 676e50c61aa7dd816dca846fd06493d2e3ae4aab +Subproject commit 1a3d9dd1870b1f45e252ff636adfd0c1f0ccf521 diff --git a/external/solanaceae_zox b/external/solanaceae_zox index 88cfc86..a678b62 160000 --- a/external/solanaceae_zox +++ b/external/solanaceae_zox @@ -1 +1 @@ -Subproject commit 88cfc8638ea850f9f1c3ed9232292684f49302df +Subproject commit a678b627639f6b043ebf7607b181a552b0d2cad0 diff --git a/external/totato b/external/totato index 4a59a83..77fffb7 160000 --- a/external/totato +++ b/external/totato @@ -1 +1 @@ -Subproject commit 4a59a83ecaa55fee07c2744ad30d4f12cf1cdd27 +Subproject commit 77fffb744e2379eefc0b1b4ce71cdfe72292a398 diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index df94b46..7493460 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -31,6 +31,7 @@ target_compile_definitions(plugin_transfer_auto_accept PUBLIC ENTT_API_IMPORT) target_link_libraries(plugin_transfer_auto_accept PUBLIC solanaceae_plugin solanaceae_util + solanaceae_object_store solanaceae_message3 solanaceae_tox_messages # sad, for filekind ) diff --git a/plugins/plugin_transfer_auto_accept.cpp b/plugins/plugin_transfer_auto_accept.cpp index 5080a5f..41b1ce9 100644 --- a/plugins/plugin_transfer_auto_accept.cpp +++ b/plugins/plugin_transfer_auto_accept.cpp @@ -32,12 +32,13 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api) } try { + auto* os = PLUG_RESOLVE_INSTANCE(ObjectStore2); auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel); auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI); // static store, could be anywhere tho // construct with fetched dependencies - g_taa = std::make_unique(*rmm, *conf); + g_taa = std::make_unique(*os, *rmm, *conf); // register types PLUG_PROVIDE_INSTANCE(TransferAutoAccept, plugin_name, g_taa.get()); diff --git a/plugins/transfer_auto_accept.cpp b/plugins/transfer_auto_accept.cpp index a7ed496..6ed7a8a 100644 --- a/plugins/transfer_auto_accept.cpp +++ b/plugins/transfer_auto_accept.cpp @@ -1,14 +1,18 @@ #include "./transfer_auto_accept.hpp" +#include + #include // for comp transfer tox filekind (TODO: generalize -> content system?) -#include +#include #include #include -TransferAutoAccept::TransferAutoAccept(RegistryMessageModel& rmm, ConfigModelI& conf) : _rmm(rmm), _conf(conf) { +TransferAutoAccept::TransferAutoAccept(ObjectStore2& os, RegistryMessageModel& rmm, ConfigModelI& conf) : _os(os), _rmm(rmm), _conf(conf) { + //_os.subscribe(this, ObjectStore_Event::object_update); + _rmm.subscribe(this, RegistryMessageModel_Event::message_construct); _rmm.subscribe(this, RegistryMessageModel_Event::message_updated); @@ -28,59 +32,90 @@ TransferAutoAccept::TransferAutoAccept(RegistryMessageModel& rmm, ConfigModelI& void TransferAutoAccept::iterate(void) { for (auto& it : _accept_queue) { - if (it.all_of()) { + if (it.all_of()) { continue; // already accepted } - it.emplace( + it.emplace( // TODO: contact to entry _conf.get_string("TransferAutoAccept", "save_path").value_or("tmp_save_dir"), false ); std::cout << "TAA: auto accepted transfer\n"; - _rmm.throwEventUpdate(it); + _os.throwEventUpdate(it); + //_rmm.throwEventUpdate(it); } _accept_queue.clear(); } -void TransferAutoAccept::checkMsg(Message3Handle h) { - if (h.all_of()) { +void TransferAutoAccept::checkObj(ObjectHandle o) { + if (o.all_of()) { return; // already accepted } - if (!h.all_of()) { + if (o.all_of()) { + return; // alreay have + } + + //if (!h.all_of()) { + // TODO: tag receiving ?? + if (!o.all_of()) { return; } + if (!o.any_of()) { + return; // dont know enough + } + // dont touch avatars for now - if (h.all_of() && h.get().kind == 1) { + // TODO: more generic file types?? + if (const auto* fk = o.try_get(); fk != nullptr && fk->kind != 0) { return; } - const auto& file_info = h.get(); + uint64_t total_size {0u}; + if (const auto* si = o.try_get(); si != nullptr) { + if (si->file_name.empty()) { + return; // bad file + } + total_size = si->file_size; + } else if (const auto* ci = o.try_get(); ci != nullptr) { + if (ci->file_list.empty() || ci->file_list.front().file_name.empty()) { + return; // bad file + } + total_size = ci->total_size; + } + + //const auto& file_info = h.get(); // TODO: contact to entry - if (file_info.total_size > uint64_t(_conf.get_int("TransferAutoAccept", "autoaccept_limit").value_or(1024*1024))) { + if (total_size > uint64_t(_conf.get_int("TransferAutoAccept", "autoaccept_limit").value_or(1024*1024))) { return; // too large } - if (file_info.file_list.empty() || file_info.file_list.front().file_name.empty()) { - return; // bad file + _accept_queue.push_back(o); +} + +void TransferAutoAccept::checkMsg(Message3Handle h) { + if (!h.all_of()) { + return; } - _accept_queue.push_back(h); + checkObj(h.get().o); } bool TransferAutoAccept::onEvent(const Message::Events::MessageConstruct& e) { - //std::cout << "TAA: msg c\n"; checkMsg(e.e); - return false; } bool TransferAutoAccept::onEvent(const Message::Events::MessageUpdated& e) { - //std::cout << "TAA: msg u\n"; checkMsg(e.e); - + return false; +} + +bool TransferAutoAccept::onEvent(const ObjectStore::Events::ObjectUpdate&) { + // too expensive rn + //checkObj(e.e); return false; } diff --git a/plugins/transfer_auto_accept.hpp b/plugins/transfer_auto_accept.hpp index fcfe5ec..80624b1 100644 --- a/plugins/transfer_auto_accept.hpp +++ b/plugins/transfer_auto_accept.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -7,25 +8,29 @@ // fwd struct ConfigModelI; -class TransferAutoAccept : public RegistryMessageModelEventI { +class TransferAutoAccept : public RegistryMessageModelEventI, public ObjectStoreEventI { + ObjectStore2& _os; RegistryMessageModel& _rmm; //ContactModelI& _cm; ConfigModelI& _conf; - std::vector _accept_queue; + std::vector _accept_queue; public: - TransferAutoAccept(RegistryMessageModel& rmm, ConfigModelI& conf); + TransferAutoAccept(ObjectStore2& os, RegistryMessageModel& rmm, ConfigModelI& conf); // TODO: iterate void iterate(void); protected: + void checkObj(ObjectHandle h); void checkMsg(Message3Handle h); protected: // mm bool onEvent(const Message::Events::MessageConstruct& e) override; bool onEvent(const Message::Events::MessageUpdated& e) override; + protected: // os + bool onEvent(const ObjectStore::Events::ObjectUpdate& e) override; };