add contact id to meta

This commit is contained in:
Green Sky 2024-02-15 00:35:39 +01:00
parent aa7a5d6013
commit d278391528
No known key found for this signature in database
3 changed files with 35 additions and 2 deletions

View File

@ -2,6 +2,7 @@
#include <solanaceae/util/utils.hpp>
#include <solanaceae/contact/components.hpp>
#include <solanaceae/message3/components.hpp>
#include <nlohmann/json.hpp>
@ -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<FragComp::MessagesContact*>(comp);
out["id"] = r_comp.id;
return true;
}
void MessageFragmentStore::handleMessage(const Message3Handle& m) {
if (!static_cast<bool>(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<Contact3>();
if (_cr.all_of<Contact::Components::ID>(msg_reg_contact)) {
fh.emplace<FragComp::MessagesContact>(_cr.get<Contact::Components::ID>(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<FragComp::MessagesTSRange>(serl_json_msg_ts_range);
_fs._sc.registerSerializerJson<FragComp::MessagesContact>(serl_json_msg_c_id);
_sc.registerSerializerJson<Message::Components::Timestamp>(serl_json_default<Message::Components::Timestamp>);
_sc.registerSerializerJson<Message::Components::TimestampProcessed>(serl_json_default<Message::Components::TimestampProcessed>);

View File

@ -7,6 +7,7 @@
#include <entt/entity/registry.hpp>
#include <entt/container/dense_map.hpp>
#include <solanaceae/contact/contact_model3.hpp>
#include <solanaceae/message3/registry_message_model.hpp>
#include <queue>
@ -29,6 +30,10 @@ namespace Fragment::Components {
uint64_t begin {0};
uint64_t end {0};
};
struct MessagesContact {
std::vector<uint8_t> 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
);

View File

@ -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),