diff --git a/src/fragment_store/message_fragment_store.cpp b/src/fragment_store/message_fragment_store.cpp index c1050a9..c886c21 100644 --- a/src/fragment_store/message_fragment_store.cpp +++ b/src/fragment_store/message_fragment_store.cpp @@ -4,6 +4,7 @@ #include #include +#include #include @@ -205,6 +206,8 @@ void MessageFragmentStore::handleMessage(const Message3Handle& m) { // on new and update: mark as fragment dirty } +// assumes new frag +// need update from frag void MessageFragmentStore::loadFragment(Message3Registry& reg, FragmentHandle fh) { std::cout << "MFS: loadFragment\n"; const auto j = _fs.loadFromStorageNJ(fh); @@ -236,11 +239,28 @@ void MessageFragmentStore::loadFragment(Message3Registry& reg, FragmentHandle fh new_real_msg.emplace_or_replace(fh.get()); - // TODO: dup checking - const bool is_dup {false}; - // dup check (hacky, specific to protocols) - if (is_dup) { + Message3 dup_msg {entt::null}; + { + // get comparator from contact + if (reg.ctx().contains()) { + const auto c = reg.ctx().get(); + if (_cr.all_of(c)) { + auto& comp = _cr.get(c).comp; + // walking EVERY existing message OOF + // this needs optimizing + for (const Message3 other_msg : reg.view()) { + if (comp({reg, other_msg}, new_real_msg)) { + // dup + dup_msg = other_msg; + break; + } + } + } + } + } + + if (reg.valid(dup_msg)) { // -> merge with preexisting // -> throw update reg.destroy(new_real_msg);