move time to util and contact timestamp attempt
This commit is contained in:
parent
cd196562af
commit
353a8199ae
@ -1,5 +1,7 @@
|
||||
#include "./tox_contact_model2.hpp"
|
||||
|
||||
#include <solanaceae/util/time.hpp>
|
||||
|
||||
#include <solanaceae/toxcore/tox_interface.hpp>
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
|
||||
@ -184,6 +186,19 @@ Contact3Handle ToxContactModel2::getContactFriend(uint32_t friend_number) {
|
||||
_cr.emplace_or_replace<Contact::Components::Name>(c, _t.toxFriendGetName(friend_number).value_or("<unk>"));
|
||||
_cr.emplace_or_replace<Contact::Components::StatusText>(c, _t.toxFriendGetStatusMessage(friend_number).value_or("")).fillFirstLineLength();
|
||||
|
||||
const auto ts = getTimeMS();
|
||||
|
||||
if (!_cr.all_of<Contact::Components::LastSeen>(c)) {
|
||||
auto lo_opt = _t.toxFriendGetLastOnline(friend_number);
|
||||
if (lo_opt.has_value()) {
|
||||
_cr.emplace_or_replace<Contact::Components::LastSeen>(c, lo_opt.value()*1000ull);
|
||||
}
|
||||
}
|
||||
|
||||
if (!_cr.all_of<Contact::Components::FirstSeen>(c)) {
|
||||
_cr.emplace_or_replace<Contact::Components::FirstSeen>(c, std::min(_cr.get<Contact::Components::LastSeen>(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<Contact::Components::ToxFriendEphemeral>();
|
||||
} else {
|
||||
const auto ts = getTimeMS();
|
||||
|
||||
_cr.emplace_or_replace<Contact::Components::LastSeen>(c, ts);
|
||||
|
||||
if (!_cr.all_of<Contact::Components::FirstSeen>(c)) {
|
||||
_cr.emplace_or_replace<Contact::Components::FirstSeen>(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<Contact::Components::LastSeen>(c, ts);
|
||||
|
||||
if (!_cr.all_of<Contact::Components::FirstSeen>(c)) {
|
||||
_cr.emplace_or_replace<Contact::Components::FirstSeen>(c, ts);
|
||||
}
|
||||
|
||||
// update name
|
||||
const auto name_opt = std::get<0>(_t.toxGroupPeerGetName(group_number, peer_number));
|
||||
if (name_opt.has_value()) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "./tox_message_manager.hpp"
|
||||
|
||||
#include <solanaceae/util/time.hpp>
|
||||
|
||||
#include <solanaceae/toxcore/tox_interface.hpp>
|
||||
|
||||
#include <solanaceae/contact/components.hpp>
|
||||
@ -87,7 +89,7 @@ bool ToxMessageManager::sendText(const Contact3 c, std::string_view message, boo
|
||||
const Contact3 c_self = _cr.get<Contact::Components::Self>(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<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
|
||||
@ -248,6 +250,8 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Friend_Message* e) {
|
||||
|
||||
reg.emplace<Message::Components::TagUnread>(new_msg_e);
|
||||
|
||||
c.emplace_or_replace<Contact::Components::LastActivity>(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<Contact::Components::Self>().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<const char*>(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<Contact::Components::LastActivity>(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<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";
|
||||
@ -395,6 +401,8 @@ bool ToxMessageManager::onToxEvent(const Tox_Event_Group_Private_Message* e) {
|
||||
rtr.try_emplace(c, ts);
|
||||
}
|
||||
|
||||
c.emplace_or_replace<Contact::Components::LastActivity>(ts);
|
||||
|
||||
_rmm.throwEventConstruct(reg, new_msg_e);
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "./tox_transfer_manager.hpp"
|
||||
|
||||
#include <solanaceae/util/time.hpp>
|
||||
|
||||
#include <solanaceae/toxcore/tox_interface.hpp>
|
||||
|
||||
#include <solanaceae/file/file2_std.hpp>
|
||||
@ -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<Contact::Components::Self>(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";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user