From 49f643a7984049410d9618f697a95912f218923f Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 18 Apr 2024 15:16:44 +0200 Subject: [PATCH] adjust for root private and group and properly fill ParentOf and Parent --- .../tox_contacts/tox_contact_model2.cpp | 32 +++++++++++++------ .../tox_contacts/tox_contact_model2.hpp | 1 + 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/solanaceae/tox_contacts/tox_contact_model2.cpp b/solanaceae/tox_contacts/tox_contact_model2.cpp index 9d29c9a..c2f5b76 100644 --- a/solanaceae/tox_contacts/tox_contact_model2.cpp +++ b/solanaceae/tox_contacts/tox_contact_model2.cpp @@ -28,19 +28,19 @@ ToxContactModel2::ToxContactModel2(Contact3Registry& cr, ToxI& t, ToxEventProvid _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_EXIT); _tep.subscribe(this, Tox_Event_Type::TOX_EVENT_GROUP_PEER_NAME); + // add tox profile root + _root = _cr.create(); + _cr.emplace(_root); + _cr.emplace(_root, this); // add self - Contact3 c = entt::null; - // TODO: if self exists - - c = _cr.create(); - _cr.emplace(c, this); - _cr.emplace(c); - _cr.emplace(c, _t.toxSelfGetName()); + _friend_self = _cr.create(); + _cr.emplace(_friend_self, this); + _cr.emplace(_friend_self, _root); + _cr.emplace(_friend_self); + _cr.emplace(_friend_self, _t.toxSelfGetName()); // TODO: can contact with id preexist here? - _cr.emplace(c, _t.toxSelfGetPublicKey()); - - _friend_self = c; + _cr.emplace(_friend_self, _t.toxSelfGetPublicKey()); // fill in contacts for (const uint32_t f_id : _t.toxSelfGetFriendList()) { @@ -172,6 +172,9 @@ Contact3Handle ToxContactModel2::getContactFriend(uint32_t friend_number) { _cr.emplace_or_replace(c, this); _cr.emplace_or_replace(c, friend_number); _cr.emplace_or_replace(c, f_key); + _cr.emplace_or_replace(c, _root); + _cr.emplace_or_replace(c).subs.assign({_friend_self, c}); + _cr.emplace_or_replace(c); _cr.emplace_or_replace(c, _friend_self); _cr.emplace_or_replace(c, _t.toxFriendGetName(friend_number).value_or("")); @@ -233,9 +236,11 @@ Contact3Handle ToxContactModel2::getContactGroup(uint32_t group_number) { _cr.emplace_or_replace(c, this); _cr.emplace_or_replace(c); + _cr.emplace_or_replace(c, _root); _cr.emplace_or_replace(c); // start empty _cr.emplace_or_replace(c, group_number); _cr.emplace_or_replace(c, g_key); + _cr.emplace_or_replace(c); _cr.emplace_or_replace(c, _t.toxGroupGetName(group_number).value_or("")); _cr.emplace_or_replace( c, @@ -361,6 +366,7 @@ Contact3Handle ToxContactModel2::getContactGroupPeer(uint32_t group_number, uint _cr.emplace_or_replace(c, this); _cr.emplace_or_replace(c, group_number, peer_number); _cr.emplace_or_replace(c, g_key, g_p_key); + _cr.emplace_or_replace(c); const auto name_opt = std::get<0>(_t.toxGroupPeerGetName(group_number, peer_number)); if (name_opt.has_value()) { _cr.emplace_or_replace(c, name_opt.value()); @@ -434,6 +440,7 @@ Contact3Handle ToxContactModel2::getContactGroupPeer(uint32_t group_number, cons _cr.emplace_or_replace(c, this); //_cr.emplace_or_replace(c, group_number, peer_number); _cr.emplace_or_replace(c, g_key, peer_key); + _cr.emplace_or_replace(c); //_cr.emplace_or_replace(c, ""); //_cr.emplace_or_replace(c, std::get<0>(_t.toxGroupPeerGetName(group_number, peer_number)).value_or("")); @@ -528,6 +535,9 @@ bool ToxContactModel2::onToxEvent(const Tox_Event_Friend_Request* e) { _cr.emplace_or_replace(c); _cr.emplace_or_replace(c, this); _cr.emplace_or_replace(c, pub_key); + _cr.emplace_or_replace(c, _root); + _cr.emplace_or_replace(c).subs.assign({_friend_self, c}); + _cr.emplace_or_replace(c); _cr.emplace_or_replace(c, _friend_self); std::cout << "TCM2: created friend contact (requested)\n"; @@ -579,7 +589,9 @@ bool ToxContactModel2::onToxEvent(const Tox_Event_Group_Invite* e) { _cr.emplace_or_replace(c, true, true); _cr.emplace_or_replace(c); _cr.emplace_or_replace(c, this); + _cr.emplace_or_replace(c, _root); _cr.emplace_or_replace(c, chat_id); + _cr.emplace_or_replace(c); _cr.emplace_or_replace(c, std::string(group_name)); auto& ir = _cr.emplace(c); diff --git a/solanaceae/tox_contacts/tox_contact_model2.hpp b/solanaceae/tox_contacts/tox_contact_model2.hpp index 868c757..7249b16 100644 --- a/solanaceae/tox_contacts/tox_contact_model2.hpp +++ b/solanaceae/tox_contacts/tox_contact_model2.hpp @@ -14,6 +14,7 @@ class ToxContactModel2 : public ContactModel3I, public ToxEventI { ToxI& _t; ToxEventProviderI& _tep; + Contact3 _root; Contact3 _friend_self; float _group_status_timer {0.f};