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
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:
parent
e497941b18
commit
1efab248ca
2
external/solanaceae_message3
vendored
2
external/solanaceae_message3
vendored
@ -1 +1 @@
|
||||
Subproject commit f1dd5107f820fe86cb6b6b9ca22d42e0a3a3cf30
|
||||
Subproject commit 9728f71c9833baa65995e19e993d3450da750c20
|
2
external/solanaceae_ngc_ft1
vendored
2
external/solanaceae_ngc_ft1
vendored
@ -1 +1 @@
|
||||
Subproject commit 54ace9d0b2e98d3b3ff70bd9bc7821b1d150dfdc
|
||||
Subproject commit 6da1f9afca264cf99d124238e95e49b0ed489284
|
2
external/solanaceae_object_store
vendored
2
external/solanaceae_object_store
vendored
@ -1 +1 @@
|
||||
Subproject commit 4605d64df28c45096cef7748d5c143e942aefeb1
|
||||
Subproject commit 2801fc21fbd6f69479f6638ab1725d00238698f8
|
2
external/solanaceae_tox
vendored
2
external/solanaceae_tox
vendored
@ -1 +1 @@
|
||||
Subproject commit 676e50c61aa7dd816dca846fd06493d2e3ae4aab
|
||||
Subproject commit 1a3d9dd1870b1f45e252ff636adfd0c1f0ccf521
|
2
external/solanaceae_zox
vendored
2
external/solanaceae_zox
vendored
@ -1 +1 @@
|
||||
Subproject commit 88cfc8638ea850f9f1c3ed9232292684f49302df
|
||||
Subproject commit a678b627639f6b043ebf7607b181a552b0d2cad0
|
2
external/totato
vendored
2
external/totato
vendored
@ -1 +1 @@
|
||||
Subproject commit 4a59a83ecaa55fee07c2744ad30d4f12cf1cdd27
|
||||
Subproject commit 77fffb744e2379eefc0b1b4ce71cdfe72292a398
|
@ -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
|
||||
)
|
||||
|
@ -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<TransferAutoAccept>(*rmm, *conf);
|
||||
g_taa = std::make_unique<TransferAutoAccept>(*os, *rmm, *conf);
|
||||
|
||||
// register types
|
||||
PLUG_PROVIDE_INSTANCE(TransferAutoAccept, plugin_name, g_taa.get());
|
||||
|
@ -1,14 +1,18 @@
|
||||
#include "./transfer_auto_accept.hpp"
|
||||
|
||||
#include <solanaceae/object_store/meta_components_file.hpp>
|
||||
|
||||
#include <solanaceae/message3/components.hpp>
|
||||
// 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 <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_updated);
|
||||
|
||||
@ -28,59 +32,90 @@ TransferAutoAccept::TransferAutoAccept(RegistryMessageModel& rmm, ConfigModelI&
|
||||
|
||||
void TransferAutoAccept::iterate(void) {
|
||||
for (auto& it : _accept_queue) {
|
||||
if (it.all_of<Message::Components::Transfer::ActionAccept>()) {
|
||||
if (it.all_of<ObjComp::Ephemeral::File::ActionTransferAccept>()) {
|
||||
continue; // already accepted
|
||||
}
|
||||
|
||||
it.emplace<Message::Components::Transfer::ActionAccept>(
|
||||
it.emplace<ObjComp::Ephemeral::File::ActionTransferAccept>(
|
||||
// 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<Message::Components::Transfer::ActionAccept>()) {
|
||||
void TransferAutoAccept::checkObj(ObjectHandle o) {
|
||||
if (o.all_of<ObjComp::Ephemeral::File::ActionTransferAccept>()) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (!o.any_of<ObjComp::F::SingleInfo, ObjComp::F::CollectionInfo>()) {
|
||||
return; // dont know enough
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
_accept_queue.push_back(h);
|
||||
void TransferAutoAccept::checkMsg(Message3Handle h) {
|
||||
if (!h.all_of<Message::Components::MessageFileObject>()) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkObj(h.get<Message::Components::MessageFileObject>().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;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <solanaceae/object_store/object_store.hpp>
|
||||
#include <solanaceae/message3/registry_message_model.hpp>
|
||||
|
||||
#include <vector>
|
||||
@ -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<Message3Handle> _accept_queue;
|
||||
std::vector<ObjectHandle> _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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user