From d2783915283b8a774d8e70336ec433af68b2246c Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 15 Feb 2024 00:35:39 +0100 Subject: [PATCH] add contact id to meta --- src/fragment_store/message_fragment_store.cpp | 28 ++++++++++++++++++- src/fragment_store/message_fragment_store.hpp | 7 +++++ src/main_screen.cpp | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/fragment_store/message_fragment_store.cpp b/src/fragment_store/message_fragment_store.cpp index 8d899a8..cba9b6b 100644 --- a/src/fragment_store/message_fragment_store.cpp +++ b/src/fragment_store/message_fragment_store.cpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -63,6 +64,20 @@ static bool serl_json_msg_ts_range(void* comp, nlohmann::json& out) { return true; } +static bool serl_json_msg_c_id(void* comp, nlohmann::json& out) { + if (comp == nullptr) { + return false; + } + + out = nlohmann::json::object(); + + auto& r_comp = *reinterpret_cast(comp); + + out["id"] = r_comp.id; + + return true; +} + void MessageFragmentStore::handleMessage(const Message3Handle& m) { if (!static_cast(m)) { return; // huh? @@ -153,6 +168,15 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) { new_ts_range.begin = msg_ts; new_ts_range.end = msg_ts; + { + const auto msg_reg_contact = m.registry()->ctx().get(); + if (_cr.all_of(msg_reg_contact)) { + fh.emplace(_cr.get(msg_reg_contact).data); + } else { + // ? rage quit? + } + } + fuid_open.emplace_back(Message::Components::OpenFragments::OpenFrag{msg_ts, msg_ts, fragment_uid}); std::cout << "MFS: created new fragment " << bin2hex(fragment_uid) << "\n"; @@ -177,14 +201,16 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) { } MessageFragmentStore::MessageFragmentStore( + Contact3Registry& cr, RegistryMessageModel& rmm, FragmentStore& fs -) : _rmm(rmm), _fs(fs) { +) : _cr(cr), _rmm(rmm), _fs(fs) { _rmm.subscribe(this, RegistryMessageModel_Event::message_construct); _rmm.subscribe(this, RegistryMessageModel_Event::message_updated); _rmm.subscribe(this, RegistryMessageModel_Event::message_destroy); _fs._sc.registerSerializerJson(serl_json_msg_ts_range); + _fs._sc.registerSerializerJson(serl_json_msg_c_id); _sc.registerSerializerJson(serl_json_default); _sc.registerSerializerJson(serl_json_default); diff --git a/src/fragment_store/message_fragment_store.hpp b/src/fragment_store/message_fragment_store.hpp index d7112a5..58ded02 100644 --- a/src/fragment_store/message_fragment_store.hpp +++ b/src/fragment_store/message_fragment_store.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -29,6 +30,10 @@ namespace Fragment::Components { uint64_t begin {0}; uint64_t end {0}; }; + + struct MessagesContact { + std::vector id; + }; } // Fragment::Components struct MessageSerializerCallbacks : public SerializerCallbacks { @@ -41,6 +46,7 @@ struct MessageSerializerCallbacks : public SerializerCallbacks { // on delete: mark as fragment dirty? class MessageFragmentStore : public RegistryMessageModelEventI { protected: + Contact3Registry& _cr; RegistryMessageModel& _rmm; FragmentStore& _fs; @@ -58,6 +64,7 @@ class MessageFragmentStore : public RegistryMessageModelEventI { public: MessageFragmentStore( + Contact3Registry& cr, RegistryMessageModel& rmm, FragmentStore& fs ); diff --git a/src/main_screen.cpp b/src/main_screen.cpp index 07c4d06..a17fd2d 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -14,7 +14,7 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, std::string save_path, std::stri renderer(renderer_), rmm(cr), mts(rmm), - mfs(rmm, fs), + mfs(cr, rmm, fs), tc(save_path, save_password), tpi(tc.getTox()), ad(tc),