hacking msg comp in contact, will be moved to tox_messages when contact events are impl

This commit is contained in:
Green Sky 2024-02-17 14:33:11 +01:00
parent b2a3cb7052
commit 2059577fc2
No known key found for this signature in database
2 changed files with 37 additions and 0 deletions

View File

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

View File

@ -3,6 +3,11 @@
#include <solanaceae/toxcore/tox_interface.hpp>
#include <solanaceae/contact/components.hpp>
// TODO: move
#include <solanaceae/message3/contact_components.hpp>
#include <solanaceae/message3/components.hpp>
#include <solanaceae/tox_messages/components.hpp>
#include "./components.hpp"
#include <algorithm>
@ -218,6 +223,36 @@ Contact3Handle ToxContactModel2::getContactGroup(uint32_t group_number) {
: Contact::Components::ConnectionState::State::disconnected
);
// TODO: remove and add OnNewContact
_cr.emplace<Contact::Components::MessageIsSame>(c,
[](Message3Handle lh, Message3Handle rh) -> bool {
if (!lh.all_of<Message::Components::ToxGroupMessageID>() || !rh.all_of<Message::Components::ToxGroupMessageID>()) {
return false; // cant compare
}
// assuming same group here
// should eliminate most messages
if (lh.get<Message::Components::ToxGroupMessageID>().id != rh.get<Message::Components::ToxGroupMessageID>().id) {
return false; // different id
}
// we get this check for free
if (lh.get<Message::Components::ContactFrom>().c != rh.get<Message::Components::ContactFrom>().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<Message::Components::Timestamp>().ts) - int64_t(rh.get<Message::Components::Timestamp>().ts)) > _max_age_difference_ms) {
return false;
}
return true;
}
);
auto self_opt = _t.toxGroupSelfGetPeerId(group_number);
if (self_opt.has_value()) {
_cr.emplace<Contact::Components::Self>(c, getContactGroupPeer(group_number, self_opt.value()));