sync and port with file msg -> obj refactor
Some checks failed
ContinuousDelivery / linux-ubuntu (push) Failing after 3m16s
ContinuousIntegration / linux (push) Successful in 2m44s
ContinuousIntegration / android (push) Failing after 5m25s
ContinuousDelivery / windows (push) Has been cancelled
ContinuousIntegration / macos (push) Has been cancelled
ContinuousIntegration / windows (push) Has been cancelled
ContinuousDelivery / release (push) Has been cancelled

This commit is contained in:
Green Sky 2024-07-31 20:07:14 +02:00
parent e497941b18
commit 1efab248ca
No known key found for this signature in database
10 changed files with 70 additions and 28 deletions

@ -1 +1 @@
Subproject commit f1dd5107f820fe86cb6b6b9ca22d42e0a3a3cf30 Subproject commit 9728f71c9833baa65995e19e993d3450da750c20

@ -1 +1 @@
Subproject commit 54ace9d0b2e98d3b3ff70bd9bc7821b1d150dfdc Subproject commit 6da1f9afca264cf99d124238e95e49b0ed489284

@ -1 +1 @@
Subproject commit 4605d64df28c45096cef7748d5c143e942aefeb1 Subproject commit 2801fc21fbd6f69479f6638ab1725d00238698f8

@ -1 +1 @@
Subproject commit 676e50c61aa7dd816dca846fd06493d2e3ae4aab Subproject commit 1a3d9dd1870b1f45e252ff636adfd0c1f0ccf521

@ -1 +1 @@
Subproject commit 88cfc8638ea850f9f1c3ed9232292684f49302df Subproject commit a678b627639f6b043ebf7607b181a552b0d2cad0

2
external/totato vendored

@ -1 +1 @@
Subproject commit 4a59a83ecaa55fee07c2744ad30d4f12cf1cdd27 Subproject commit 77fffb744e2379eefc0b1b4ce71cdfe72292a398

View File

@ -31,6 +31,7 @@ target_compile_definitions(plugin_transfer_auto_accept PUBLIC ENTT_API_IMPORT)
target_link_libraries(plugin_transfer_auto_accept PUBLIC target_link_libraries(plugin_transfer_auto_accept PUBLIC
solanaceae_plugin solanaceae_plugin
solanaceae_util solanaceae_util
solanaceae_object_store
solanaceae_message3 solanaceae_message3
solanaceae_tox_messages # sad, for filekind solanaceae_tox_messages # sad, for filekind
) )

View File

@ -32,12 +32,13 @@ SOLANA_PLUGIN_EXPORT uint32_t solana_plugin_start(struct SolanaAPI* solana_api)
} }
try { try {
auto* os = PLUG_RESOLVE_INSTANCE(ObjectStore2);
auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel); auto* rmm = PLUG_RESOLVE_INSTANCE(RegistryMessageModel);
auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI); auto* conf = PLUG_RESOLVE_INSTANCE(ConfigModelI);
// static store, could be anywhere tho // static store, could be anywhere tho
// construct with fetched dependencies // construct with fetched dependencies
g_taa = std::make_unique<TransferAutoAccept>(*rmm, *conf); g_taa = std::make_unique<TransferAutoAccept>(*os, *rmm, *conf);
// register types // register types
PLUG_PROVIDE_INSTANCE(TransferAutoAccept, plugin_name, g_taa.get()); PLUG_PROVIDE_INSTANCE(TransferAutoAccept, plugin_name, g_taa.get());

View File

@ -1,14 +1,18 @@
#include "./transfer_auto_accept.hpp" #include "./transfer_auto_accept.hpp"
#include <solanaceae/object_store/meta_components_file.hpp>
#include <solanaceae/message3/components.hpp> #include <solanaceae/message3/components.hpp>
// for comp transfer tox filekind (TODO: generalize -> content system?) // for comp transfer tox filekind (TODO: generalize -> content system?)
#include <solanaceae/tox_messages/components.hpp> #include <solanaceae/tox_messages/obj_components.hpp>
#include <solanaceae/util/config_model.hpp> #include <solanaceae/util/config_model.hpp>
#include <iostream> #include <iostream>
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_construct);
_rmm.subscribe(this, RegistryMessageModel_Event::message_updated); _rmm.subscribe(this, RegistryMessageModel_Event::message_updated);
@ -28,59 +32,90 @@ TransferAutoAccept::TransferAutoAccept(RegistryMessageModel& rmm, ConfigModelI&
void TransferAutoAccept::iterate(void) { void TransferAutoAccept::iterate(void) {
for (auto& it : _accept_queue) { for (auto& it : _accept_queue) {
if (it.all_of<Message::Components::Transfer::ActionAccept>()) { if (it.all_of<ObjComp::Ephemeral::File::ActionTransferAccept>()) {
continue; // already accepted continue; // already accepted
} }
it.emplace<Message::Components::Transfer::ActionAccept>( it.emplace<ObjComp::Ephemeral::File::ActionTransferAccept>(
// TODO: contact to entry // TODO: contact to entry
_conf.get_string("TransferAutoAccept", "save_path").value_or("tmp_save_dir"), _conf.get_string("TransferAutoAccept", "save_path").value_or("tmp_save_dir"),
false false
); );
std::cout << "TAA: auto accepted transfer\n"; std::cout << "TAA: auto accepted transfer\n";
_rmm.throwEventUpdate(it); _os.throwEventUpdate(it);
//_rmm.throwEventUpdate(it);
} }
_accept_queue.clear(); _accept_queue.clear();
} }
void TransferAutoAccept::checkMsg(Message3Handle h) { void TransferAutoAccept::checkObj(ObjectHandle o) {
if (h.all_of<Message::Components::Transfer::ActionAccept>()) { if (o.all_of<ObjComp::Ephemeral::File::ActionTransferAccept>()) {
return; // already accepted return; // already accepted
} }
if (!h.all_of<Message::Components::Transfer::TagReceiving, Message::Components::Transfer::TagPaused, Message::Components::Transfer::FileInfo>()) { if (o.all_of<ObjComp::F::TagLocalHaveAll>()) {
return; // alreay have
}
//if (!h.all_of<Message::Components::Transfer::TagReceiving, Message::Components::Transfer::TagPaused, Message::Components::Transfer::FileInfo>()) {
// TODO: tag receiving ??
if (!o.all_of</*Message::Components::Transfer::TagReceiving, */ObjComp::Ephemeral::File::TagTransferPaused>()) {
return; return;
} }
if (!o.any_of<ObjComp::F::SingleInfo, ObjComp::F::CollectionInfo>()) {
return; // dont know enough
}
// dont touch avatars for now // dont touch avatars for now
if (h.all_of<Message::Components::Transfer::FileKind>() && h.get<Message::Components::Transfer::FileKind>().kind == 1) { // TODO: more generic file types??
if (const auto* fk = o.try_get<ObjComp::Tox::FileKind>(); fk != nullptr && fk->kind != 0) {
return; return;
} }
const auto& file_info = h.get<Message::Components::Transfer::FileInfo>(); uint64_t total_size {0u};
if (const auto* si = o.try_get<ObjComp::F::SingleInfo>(); si != nullptr) {
if (si->file_name.empty()) {
return; // bad file
}
total_size = si->file_size;
} else if (const auto* ci = o.try_get<ObjComp::F::CollectionInfo>(); 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<Message::Components::Transfer::FileInfo>();
// TODO: contact to entry // 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 return; // too large
} }
if (file_info.file_list.empty() || file_info.file_list.front().file_name.empty()) { _accept_queue.push_back(o);
return; // bad file }
void TransferAutoAccept::checkMsg(Message3Handle h) {
if (!h.all_of<Message::Components::MessageFileObject>()) {
return;
} }
_accept_queue.push_back(h); checkObj(h.get<Message::Components::MessageFileObject>().o);
} }
bool TransferAutoAccept::onEvent(const Message::Events::MessageConstruct& e) { bool TransferAutoAccept::onEvent(const Message::Events::MessageConstruct& e) {
//std::cout << "TAA: msg c\n";
checkMsg(e.e); checkMsg(e.e);
return false; return false;
} }
bool TransferAutoAccept::onEvent(const Message::Events::MessageUpdated& e) { bool TransferAutoAccept::onEvent(const Message::Events::MessageUpdated& e) {
//std::cout << "TAA: msg u\n";
checkMsg(e.e); checkMsg(e.e);
return false;
}
bool TransferAutoAccept::onEvent(const ObjectStore::Events::ObjectUpdate&) {
// too expensive rn
//checkObj(e.e);
return false; return false;
} }

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <solanaceae/object_store/object_store.hpp>
#include <solanaceae/message3/registry_message_model.hpp> #include <solanaceae/message3/registry_message_model.hpp>
#include <vector> #include <vector>
@ -7,25 +8,29 @@
// fwd // fwd
struct ConfigModelI; struct ConfigModelI;
class TransferAutoAccept : public RegistryMessageModelEventI { class TransferAutoAccept : public RegistryMessageModelEventI, public ObjectStoreEventI {
ObjectStore2& _os;
RegistryMessageModel& _rmm; RegistryMessageModel& _rmm;
//ContactModelI& _cm; //ContactModelI& _cm;
ConfigModelI& _conf; ConfigModelI& _conf;
std::vector<Message3Handle> _accept_queue; std::vector<ObjectHandle> _accept_queue;
public: public:
TransferAutoAccept(RegistryMessageModel& rmm, ConfigModelI& conf); TransferAutoAccept(ObjectStore2& os, RegistryMessageModel& rmm, ConfigModelI& conf);
// TODO: iterate // TODO: iterate
void iterate(void); void iterate(void);
protected: protected:
void checkObj(ObjectHandle h);
void checkMsg(Message3Handle h); void checkMsg(Message3Handle h);
protected: // mm protected: // mm
bool onEvent(const Message::Events::MessageConstruct& e) override; bool onEvent(const Message::Events::MessageConstruct& e) override;
bool onEvent(const Message::Events::MessageUpdated& e) override; bool onEvent(const Message::Events::MessageUpdated& e) override;
protected: // os
bool onEvent(const ObjectStore::Events::ObjectUpdate& e) override;
}; };