contact 4 refactor
Some checks are pending
ContinuousDelivery / linux-ubuntu (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Waiting to run
ContinuousDelivery / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousDelivery / windows (push) Waiting to run
ContinuousDelivery / windows-asan (push) Waiting to run
ContinuousDelivery / dumpsyms (push) Blocked by required conditions
ContinuousDelivery / release (push) Blocked by required conditions
ContinuousIntegration / linux (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:arm64-v8a vcpkg_toolkit:arm64-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:armeabi-v7a vcpkg_toolkit:arm-neon-android]) (push) Waiting to run
ContinuousIntegration / android (map[ndk_abi:x86_64 vcpkg_toolkit:x64-android]) (push) Waiting to run
ContinuousIntegration / macos (push) Waiting to run
ContinuousIntegration / windows (push) Waiting to run

This commit is contained in:
Green Sky
2025-03-06 19:12:35 +01:00
parent 77a95811f2
commit c29aa523dc
24 changed files with 196 additions and 155 deletions

View File

@@ -4,6 +4,8 @@
#include <solanaceae/util/config_model.hpp>
#include <solanaceae/contact/contact_store_i.hpp>
//#include <solanaceae/message3/components.hpp>
#include <solanaceae/object_store/meta_components_file.hpp>
// for comp transfer tox filekind (TODO: generalize -> content system?)
@@ -29,11 +31,10 @@ namespace Components {
}
ToxAvatarManager::ToxAvatarManager(
//RegistryMessageModel& rmm,
ObjectStore2& os,
Contact3Registry& cr,
ContactStore4I& cs,
ConfigModelI& conf
) : /*_rmm(rmm)*/ _os(os), _os_sr(_os.newSubRef(this)), _cr(cr), _conf(conf) {
) : _os(os), _os_sr(_os.newSubRef(this)), _cs(cs), _conf(conf) {
_os_sr
.subscribe(ObjectStore_Event::object_construct)
.subscribe(ObjectStore_Event::object_update)
@@ -53,11 +54,11 @@ ToxAvatarManager::ToxAvatarManager(
{ // scan tox contacts for cached avatars
// old sts says pubkey.png
_cr.view<Contact::Components::ToxFriendPersistent>().each([this](auto c, const Contact::Components::ToxFriendPersistent& tox_pers) {
_cs.registry().view<Contact::Components::ToxFriendPersistent>().each([this](auto c, const Contact::Components::ToxFriendPersistent& tox_pers) {
addAvatarFileToContact(c, tox_pers.key);
});
_cr.view<Contact::Components::ToxGroupPersistent>().each([this](auto c, const Contact::Components::ToxGroupPersistent& tox_pers) {
_cs.registry().view<Contact::Components::ToxGroupPersistent>().each([this](auto c, const Contact::Components::ToxGroupPersistent& tox_pers) {
addAvatarFileToContact(c, tox_pers.chat_id);
});
@@ -92,20 +93,25 @@ std::string ToxAvatarManager::getAvatarPath(const ToxKey& key) const {
return file_path.generic_u8string();
}
void ToxAvatarManager::addAvatarFileToContact(const Contact3 c, const ToxKey& key) {
void ToxAvatarManager::addAvatarFileToContact(const Contact4 c, const ToxKey& key) {
const auto file_path = getAvatarPath(key);
if (std::filesystem::is_regular_file(file_path)) {
// avatar file png file exists
_cr.emplace_or_replace<Contact::Components::AvatarFile>(c, file_path);
_cr.emplace_or_replace<Contact::Components::TagAvatarInvalidate>(c);
_cs.registry().emplace_or_replace<Contact::Components::AvatarFile>(c, file_path);
_cs.registry().emplace_or_replace<Contact::Components::TagAvatarInvalidate>(c);
_cs.throwEventUpdate(c);
}
}
void ToxAvatarManager::clearAvatarFromContact(const Contact3 c) {
if (_cr.all_of<Contact::Components::AvatarFile>(c)) {
std::filesystem::remove(_cr.get<Contact::Components::AvatarFile>(c).file_path);
_cr.remove<Contact::Components::AvatarFile>(c);
_cr.emplace_or_replace<Contact::Components::TagAvatarInvalidate>(c);
void ToxAvatarManager::clearAvatarFromContact(const Contact4 c) {
auto& cr = _cs.registry();
if (cr.all_of<Contact::Components::AvatarFile>(c)) {
std::filesystem::remove(cr.get<Contact::Components::AvatarFile>(c).file_path);
cr.remove<Contact::Components::AvatarFile>(c);
cr.emplace_or_replace<Contact::Components::TagAvatarInvalidate>(c);
_cs.throwEventUpdate(c);
}
}