diff --git a/solanaceae/tox_messages/backends/tox_ft_filesystem.cpp b/solanaceae/tox_messages/backends/tox_ft_filesystem.cpp index f31d4d6..692d80e 100644 --- a/solanaceae/tox_messages/backends/tox_ft_filesystem.cpp +++ b/solanaceae/tox_messages/backends/tox_ft_filesystem.cpp @@ -11,20 +11,23 @@ namespace Backends { ToxFTFilesystem::ToxFTFilesystem( ObjectStore2& os -) : StorageBackendI::StorageBackendI(os) { +) : _os(os) { } ToxFTFilesystem::~ToxFTFilesystem(void) { } -ObjectHandle ToxFTFilesystem::newObject(ByteSpan id) { +ObjectHandle ToxFTFilesystem::newObject(ByteSpan id, bool throw_construct) { ObjectHandle o{_os.registry(), _os.registry().create()}; - o.emplace(this); + o.emplace(this); + o.emplace(this); o.emplace(std::vector{id}); //o.emplace(object_file_path.generic_u8string()); - _os.throwEventConstruct(o); + if (throw_construct) { + _os.throwEventConstruct(o); + } return o; } diff --git a/solanaceae/tox_messages/backends/tox_ft_filesystem.hpp b/solanaceae/tox_messages/backends/tox_ft_filesystem.hpp index 9723880..8c9e026 100644 --- a/solanaceae/tox_messages/backends/tox_ft_filesystem.hpp +++ b/solanaceae/tox_messages/backends/tox_ft_filesystem.hpp @@ -4,13 +4,15 @@ namespace Backends { -struct ToxFTFilesystem : public StorageBackendI { +struct ToxFTFilesystem : public StorageBackendIMeta, public StorageBackendIFile2 { + ObjectStore2& _os; + ToxFTFilesystem( ObjectStore2& os ); ~ToxFTFilesystem(void); - ObjectHandle newObject(ByteSpan id) override; + ObjectHandle newObject(ByteSpan id, bool throw_construct = true) override; std::unique_ptr file2(Object o, FILE2_FLAGS flags) override; }; diff --git a/solanaceae/tox_messages/tox_transfer_manager.cpp b/solanaceae/tox_messages/tox_transfer_manager.cpp index f47494e..b6eaba1 100644 --- a/solanaceae/tox_messages/tox_transfer_manager.cpp +++ b/solanaceae/tox_messages/tox_transfer_manager.cpp @@ -11,6 +11,8 @@ #include #include "./msg_components.hpp" #include "./obj_components.hpp" +#include "solanaceae/object_store/meta_components.hpp" +#include "solanaceae/util/span.hpp" #include @@ -146,8 +148,7 @@ Message3Handle ToxTransferManager::toxSendFilePath(const Contact3 c, uint32_t fi return {}; } - // TODO: move this to backend - ObjectHandle o {_os.registry(), _os.registry().create()}; + auto o = _ftb.newObject(ByteSpan{file_id}, false); o.emplace(); o.emplace(); @@ -159,8 +160,6 @@ Message3Handle ToxTransferManager::toxSendFilePath(const Contact3 c, uint32_t fi o.emplace(std::string{file_path}); o.emplace(std::string{file_path}); // ? - o.emplace(&_ftb); - o.emplace(); // TODO: replace with better state tracking @@ -507,7 +506,7 @@ bool ToxTransferManager::onToxEvent(const Tox_Event_File_Recv* e) { auto self_c = _cr.get(c).self; - o = {_os.registry(), _os.registry().create()}; + o = _ftb.newObject(ByteSpan{f_id_opt.value()}, false); o.emplace(); o.emplace(); @@ -521,8 +520,6 @@ bool ToxTransferManager::onToxEvent(const Tox_Event_File_Recv* e) { o.emplace(); - o.emplace(&_ftb); - toxFriendLookupAdd(o); Message3Handle msg = {*reg_ptr, reg_ptr->create()};