diff --git a/solanaceae/tox_contacts/tox_contact_model2.cpp b/solanaceae/tox_contacts/tox_contact_model2.cpp index 9a7352e..557cb72 100644 --- a/solanaceae/tox_contacts/tox_contact_model2.cpp +++ b/solanaceae/tox_contacts/tox_contact_model2.cpp @@ -1,5 +1,7 @@ #include "./tox_contact_model2.hpp" +#include + #include #include @@ -184,6 +186,19 @@ Contact3Handle ToxContactModel2::getContactFriend(uint32_t friend_number) { _cr.emplace_or_replace(c, _t.toxFriendGetName(friend_number).value_or("")); _cr.emplace_or_replace(c, _t.toxFriendGetStatusMessage(friend_number).value_or("")).fillFirstLineLength(); + const auto ts = getTimeMS(); + + if (!_cr.all_of(c)) { + auto lo_opt = _t.toxFriendGetLastOnline(friend_number); + if (lo_opt.has_value()) { + _cr.emplace_or_replace(c, lo_opt.value()*1000ull); + } + } + + if (!_cr.all_of(c)) { + _cr.emplace_or_replace(c, std::min(_cr.get(c).ts, ts)); + } + std::cout << "TCM2: created friend contact " << friend_number << "\n"; return {_cr, c}; @@ -496,6 +511,14 @@ bool ToxContactModel2::onToxEvent(const Tox_Event_Friend_Connection_Status* e) { if (connection_status == TOX_CONNECTION_NONE) { c.remove(); + } else { + const auto ts = getTimeMS(); + + _cr.emplace_or_replace(c, ts); + + if (!_cr.all_of(c)) { + _cr.emplace_or_replace(c, ts); + } } return false; @@ -689,6 +712,14 @@ bool ToxContactModel2::onToxEvent(const Tox_Event_Group_Peer_Join* e) { Contact::Components::ConnectionState::State::cloud ); + const auto ts = getTimeMS(); + + _cr.emplace_or_replace(c, ts); + + if (!_cr.all_of(c)) { + _cr.emplace_or_replace(c, ts); + } + // update name const auto name_opt = std::get<0>(_t.toxGroupPeerGetName(group_number, peer_number)); if (name_opt.has_value()) { diff --git a/solanaceae/tox_messages/tox_message_manager.cpp b/solanaceae/tox_messages/tox_message_manager.cpp index f9aafb6..758e8e1 100644 --- a/solanaceae/tox_messages/tox_message_manager.cpp +++ b/solanaceae/tox_messages/tox_message_manager.cpp @@ -1,5 +1,7 @@ #include "./tox_message_manager.hpp" +#include + #include #include @@ -87,7 +89,7 @@ bool ToxMessageManager::sendText(const Contact3 c, std::string_view message, boo const Contact3 c_self = _cr.get(c).self; // get current time unix epoch utc - uint64_t ts = Message::getTimeMS(); + uint64_t ts = getTimeMS(); // TODO: split into multiple messages here, if its too long ? @@ -207,7 +209,7 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Friend_Message* e) { Tox_Message_Type type = tox_event_friend_message_get_type(e); // get current time unix epoch utc - uint64_t ts = Message::getTimeMS(); + uint64_t ts = getTimeMS(); std::string_view message {reinterpret_cast(tox_event_friend_message_get_message(e)), tox_event_friend_message_get_message_length(e)}; message = message.substr(0, message.find_first_of('\0')); // trim \0 // hi zoff @@ -248,6 +250,8 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Friend_Message* e) { reg.emplace(new_msg_e); + c.emplace_or_replace(ts); + _rmm.throwEventConstruct(reg, new_msg_e); return false; // TODO: return true? } @@ -257,7 +261,7 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Friend_Read_Receipt* e) { uint32_t msg_id = tox_event_friend_read_receipt_get_message_id(e); // get current time unix epoch utc - uint64_t ts = Message::getTimeMS(); + uint64_t ts = getTimeMS(); const auto c = _tcm.getContactFriend(friend_number); const auto self_c = c.get().self; @@ -292,7 +296,7 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Group_Message* e) { const uint32_t message_id = tox_event_group_message_get_message_id(e); const Tox_Message_Type type = tox_event_group_message_get_message_type(e); - const uint64_t ts = Message::getTimeMS(); + const uint64_t ts = getTimeMS(); auto message = std::string_view{reinterpret_cast(tox_event_group_message_get_message(e)), tox_event_group_message_get_message_length(e)}; std::cout << "TMM group message: " << message << "\n"; @@ -342,6 +346,8 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Group_Message* e) { rtr.try_emplace(c, ts); } + c.emplace_or_replace(ts); + _rmm.throwEventConstruct(reg, new_msg_e); return false; // TODO: true? } @@ -351,7 +357,7 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Group_Private_Message* e) { const uint32_t peer_number = tox_event_group_private_message_get_peer_id(e); const Tox_Message_Type type = tox_event_group_private_message_get_message_type(e); - const uint64_t ts = Message::getTimeMS(); + const uint64_t ts = getTimeMS(); auto message = std::string_view{reinterpret_cast(tox_event_group_private_message_get_message(e)), tox_event_group_private_message_get_message_length(e)}; std::cout << "TMM group private message: " << message << "\n"; @@ -395,6 +401,8 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Group_Private_Message* e) { rtr.try_emplace(c, ts); } + c.emplace_or_replace(ts); + _rmm.throwEventConstruct(reg, new_msg_e); return false; } diff --git a/solanaceae/tox_messages/tox_transfer_manager.cpp b/solanaceae/tox_messages/tox_transfer_manager.cpp index 9db8d56..f47494e 100644 --- a/solanaceae/tox_messages/tox_transfer_manager.cpp +++ b/solanaceae/tox_messages/tox_transfer_manager.cpp @@ -1,5 +1,7 @@ #include "./tox_transfer_manager.hpp" +#include + #include #include @@ -127,7 +129,7 @@ Message3Handle ToxTransferManager::toxSendFilePath(const Contact3 c, uint32_t fi } // get current time unix epoch utc - uint64_t ts = Message::getTimeMS(); + uint64_t ts = getTimeMS(); if (file_id.empty()) { file_id.resize(32); @@ -501,7 +503,7 @@ bool ToxTransferManager::onToxEvent(const Tox_Event_File_Recv* e) { } // get current time unix epoch utc - uint64_t ts = Message::getTimeMS(); + uint64_t ts = getTimeMS(); auto self_c = _cr.get(c).self; @@ -603,7 +605,7 @@ bool ToxTransferManager::onToxEvent(const Tox_Event_File_Recv_Chunk* e) { } if (data_size == 0) { - uint64_t ts = Message::getTimeMS(); + uint64_t ts = getTimeMS(); std::cout << "TTM finished friend " << friend_number << " transfer " << file_number << ", closing\n";