diff --git a/solanaceae/tox_contacts/tox_contact_model2.cpp b/solanaceae/tox_contacts/tox_contact_model2.cpp index 6316cff..78f3333 100644 --- a/solanaceae/tox_contacts/tox_contact_model2.cpp +++ b/solanaceae/tox_contacts/tox_contact_model2.cpp @@ -18,6 +18,33 @@ #include #include +static bool contact_tox_group_message_is_same(Message3Handle lh, Message3Handle rh) { + 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; +} + ToxContactModel2::ToxContactModel2(ContactStore4I& cs, ToxI& t, ToxEventProviderI& tep) : _cs(cs), _t(t), _tep_sr(tep.newSubRef(this)) { _tep_sr .subscribe(Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS) @@ -434,6 +461,7 @@ ContactHandle4 ToxContactModel2::getContactGroup(uint32_t group_number) { cr.emplace(c, g_key_opt.value()); } + // TODO: refactor and make an assure_ngc() function cr.emplace_or_replace(c, this); cr.emplace_or_replace(c); cr.emplace_or_replace(c, _root); @@ -452,34 +480,7 @@ ContactHandle4 ToxContactModel2::getContactGroup(uint32_t group_number) { ); // TODO: remove and add OnNewContact - cr.emplace_or_replace(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; - } - ); + cr.emplace_or_replace(c, contact_tox_group_message_is_same); // TODO: move after event? throw first if create? auto self_opt = _t.toxGroupSelfGetPeerId(group_number); @@ -813,6 +814,8 @@ bool ToxContactModel2::onToxEvent(const Tox_Event_Friend_Request* e) { cr.emplace_or_replace(c); cr.emplace_or_replace(c, _friend_self); + cr.emplace_or_replace(c, contact_tox_group_message_is_same); + std::cout << "TCM2: created friend contact (requested)\n"; if (created) { diff --git a/solanaceae/tox_messages/tox_transfer_manager.cpp b/solanaceae/tox_messages/tox_transfer_manager.cpp index fb3931e..4c5666a 100644 --- a/solanaceae/tox_messages/tox_transfer_manager.cpp +++ b/solanaceae/tox_messages/tox_transfer_manager.cpp @@ -10,7 +10,6 @@ #include #include #include -#include "./msg_components.hpp" #include "./obj_components.hpp" #include @@ -812,6 +811,8 @@ bool ToxTransferManager::onToxEvent(const Tox_Event_File_Recv_Control* e) { Components::TFTFile2 >(); + // TODO: canceled tag with reason?? + //_rmm.throwEventUpdate(transfer); _os.throwEventUpdate(o); } else if (control == TOX_FILE_CONTROL_PAUSE) {