update to new ngc_events and use messages time

This commit is contained in:
Green Sky 2023-12-26 21:03:49 +01:00
parent 89e74b35f8
commit c01d91144c
No known key found for this signature in database
3 changed files with 22 additions and 22 deletions

View File

@ -10,18 +10,18 @@
#include <iostream> #include <iostream>
ToxContactModel2::ToxContactModel2(Contact3Registry& cr, ToxI& t, ToxEventProviderI& tep) : _cr(cr), _t(t), _tep(tep) { ToxContactModel2::ToxContactModel2(Contact3Registry& cr, ToxI& t, ToxEventProviderI& tep) : _cr(cr), _t(t), _tep(tep) {
_tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_CONNECTION_STATUS); _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS);
_tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_STATUS); _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_STATUS);
_tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_NAME); _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_NAME);
_tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_REQUEST); _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_REQUEST);
// TODO: conf // TODO: conf
_tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_INVITE); _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_INVITE);
_tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_SELF_JOIN); _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_SELF_JOIN);
_tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_JOIN); _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_JOIN);
_tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_EXIT); _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_EXIT);
_tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_NAME); _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_NAME);
// add self // add self

View File

@ -17,7 +17,7 @@ ToxMessageManager::ToxMessageManager(RegistryMessageModel& rmm, Contact3Registry
// TODO: system messages? // TODO: system messages?
//tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_CONNECTION_STATUS); //tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_CONNECTION_STATUS);
//tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_STATUS); //tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_STATUS);
tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_MESSAGE); tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_MESSAGE);
// TODO: conf // TODO: conf
@ -25,8 +25,8 @@ ToxMessageManager::ToxMessageManager(RegistryMessageModel& rmm, Contact3Registry
//tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_JOIN); //tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_JOIN);
//tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_SELF_JOIN); //tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_SELF_JOIN);
//tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_NAME); //tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PEER_NAME);
tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_MESSAGE); tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_MESSAGE);
tep.subscribe(this, Tox_Event::TOX_EVENT_GROUP_PRIVATE_MESSAGE); tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PRIVATE_MESSAGE);
_rmm.subscribe(this, RegistryMessageModel_Event::send_text); _rmm.subscribe(this, RegistryMessageModel_Event::send_text);
} }
@ -71,7 +71,7 @@ bool ToxMessageManager::sendText(const Contact3 c, std::string_view message, boo
const Contact3 c_self = _cr.get<Contact::Components::Self>(c).self; const Contact3 c_self = _cr.get<Contact::Components::Self>(c).self;
// get current time unix epoch utc // get current time unix epoch utc
uint64_t ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); uint64_t ts = Message::getTimeMS();
auto new_msg_e = reg.create(); auto new_msg_e = reg.create();
reg.emplace<Message::Components::ContactFrom>(new_msg_e, c_self); reg.emplace<Message::Components::ContactFrom>(new_msg_e, c_self);
@ -169,7 +169,7 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Friend_Message* e) {
Tox_Message_Type type = tox_event_friend_message_get_type(e); Tox_Message_Type type = tox_event_friend_message_get_type(e);
// get current time unix epoch utc // get current time unix epoch utc
uint64_t ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); uint64_t ts = Message::getTimeMS();
std::string_view message {reinterpret_cast<const char*>(tox_event_friend_message_get_message(e)), tox_event_friend_message_get_message_length(e)}; std::string_view message {reinterpret_cast<const char*>(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 message = message.substr(0, message.find_first_of('\0')); // trim \0 // hi zoff
@ -215,7 +215,7 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Group_Message* e) {
const uint32_t message_id = tox_event_group_message_get_message_id(e); const uint32_t message_id = tox_event_group_message_get_message_id(e);
const Tox_Message_Type type = tox_event_group_message_get_type(e); const Tox_Message_Type type = tox_event_group_message_get_type(e);
uint64_t ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); const uint64_t ts = Message::getTimeMS();
auto message = std::string_view{reinterpret_cast<const char*>(tox_event_group_message_get_message(e)), tox_event_group_message_get_message_length(e)}; auto message = std::string_view{reinterpret_cast<const char*>(tox_event_group_message_get_message(e)), tox_event_group_message_get_message_length(e)};
std::cout << "TMM group message: " << message << "\n"; std::cout << "TMM group message: " << message << "\n";
@ -269,7 +269,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 uint32_t peer_number = tox_event_group_private_message_get_peer_id(e);
const Tox_Message_Type type = tox_event_group_private_message_get_type(e); const Tox_Message_Type type = tox_event_group_private_message_get_type(e);
uint64_t ts = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(); const uint64_t ts = Message::getTimeMS();
auto message = std::string_view{reinterpret_cast<const char*>(tox_event_group_private_message_get_message(e)), tox_event_group_private_message_get_message_length(e)}; auto message = std::string_view{reinterpret_cast<const char*>(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"; std::cout << "TMM group private message: " << message << "\n";

View File

@ -68,11 +68,11 @@ Message3Handle ToxTransferManager::toxFriendLookupReceiving(const uint32_t frien
} }
ToxTransferManager::ToxTransferManager(RegistryMessageModel& rmm, Contact3Registry& cr, ToxContactModel2& tcm, ToxI& t, ToxEventProviderI& tep) : _rmm(rmm), _cr(cr), _tcm(tcm), _t(t) { ToxTransferManager::ToxTransferManager(RegistryMessageModel& rmm, Contact3Registry& cr, ToxContactModel2& tcm, ToxI& t, ToxEventProviderI& tep) : _rmm(rmm), _cr(cr), _tcm(tcm), _t(t) {
tep.subscribe(this, Tox_Event::TOX_EVENT_FRIEND_CONNECTION_STATUS); tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FRIEND_CONNECTION_STATUS);
tep.subscribe(this, Tox_Event::TOX_EVENT_FILE_RECV); tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FILE_RECV);
tep.subscribe(this, Tox_Event::TOX_EVENT_FILE_RECV_CONTROL); tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FILE_RECV_CONTROL);
tep.subscribe(this, Tox_Event::TOX_EVENT_FILE_RECV_CHUNK); tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FILE_RECV_CHUNK);
tep.subscribe(this, Tox_Event::TOX_EVENT_FILE_CHUNK_REQUEST); tep.subscribe(this, Tox_Event_Type::TOX_EVENT_FILE_CHUNK_REQUEST);
_rmm.subscribe(this, RegistryMessageModel_Event::message_construct); _rmm.subscribe(this, RegistryMessageModel_Event::message_construct);
_rmm.subscribe(this, RegistryMessageModel_Event::message_updated); _rmm.subscribe(this, RegistryMessageModel_Event::message_updated);
@ -542,7 +542,7 @@ bool ToxTransferManager::onToxEvent(const Tox_Event_File_Recv_Chunk* e) {
const auto friend_number = tox_event_file_recv_chunk_get_friend_number(e); const auto friend_number = tox_event_file_recv_chunk_get_friend_number(e);
const auto file_number = tox_event_file_recv_chunk_get_file_number(e); const auto file_number = tox_event_file_recv_chunk_get_file_number(e);
const uint8_t* data = tox_event_file_recv_chunk_get_data(e); const uint8_t* data = tox_event_file_recv_chunk_get_data(e);
const auto data_size = tox_event_file_recv_chunk_get_length(e); const auto data_size = tox_event_file_recv_chunk_get_data_length(e);
const auto position = tox_event_file_recv_chunk_get_position(e); const auto position = tox_event_file_recv_chunk_get_position(e);
Message3Handle transfer = toxFriendLookupReceiving(friend_number, file_number); Message3Handle transfer = toxFriendLookupReceiving(friend_number, file_number);