diff --git a/CMakeLists.txt b/CMakeLists.txt index bf2e35d..3bd28ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,8 @@ target_link_libraries(solanaceae_tox_contacts PUBLIC solanaceae_util solanaceae_contact solanaceae_toxcore + + solanaceae_message3 # for messageissame ) add_library(solanaceae_tox_messages diff --git a/solanaceae/tox_contacts/tox_contact_model2.cpp b/solanaceae/tox_contacts/tox_contact_model2.cpp index c6c3bb1..248a47b 100644 --- a/solanaceae/tox_contacts/tox_contact_model2.cpp +++ b/solanaceae/tox_contacts/tox_contact_model2.cpp @@ -3,6 +3,11 @@ #include #include +// TODO: move +#include +#include +#include + #include "./components.hpp" #include @@ -218,6 +223,36 @@ Contact3Handle ToxContactModel2::getContactGroup(uint32_t group_number) { : Contact::Components::ConnectionState::State::disconnected ); + // TODO: remove and add OnNewContact + _cr.emplace(c, + [](Message3Handle lh, Message3Handle rh) -> bool { + if (!lh.all_of() || !rh.all_of()) { + return false; // cant compare + } + + // assuming same group here + + // should eliminate most messages + if (lh.get().id != rh.get().id) { + return false; // different id + } + + // we get this check for free + if (lh.get().c != rh.get().c) { + return false; + } + + constexpr int64_t _max_age_difference_ms {130*60*1000}; // same msgid in 130min is considered the same msg + + // how far apart the 2 timestamps can be, before they are considered different messages + if (std::abs(int64_t(lh.get().ts) - int64_t(rh.get().ts)) > _max_age_difference_ms) { + return false; + } + + return true; + } + ); + auto self_opt = _t.toxGroupSelfGetPeerId(group_number); if (self_opt.has_value()) { _cr.emplace(c, getContactGroupPeer(group_number, self_opt.value()));