From a2c0bfe5580f91ac42baa68ae3ffd1be14ed26b9 Mon Sep 17 00:00:00 2001 From: gaelle Date: Wed, 16 Apr 2025 16:26:00 +0200 Subject: [PATCH] remove friend from friendsmanager maps when created, updated, removed --- Linphone/core/friend/FriendCore.cpp | 5 ++-- Linphone/model/friend/FriendsManager.cpp | 33 ++++++++++++++++++++++++ Linphone/model/friend/FriendsManager.hpp | 1 - 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Linphone/core/friend/FriendCore.cpp b/Linphone/core/friend/FriendCore.cpp index 1e6d8086b..1b3e2e13d 100644 --- a/Linphone/core/friend/FriendCore.cpp +++ b/Linphone/core/friend/FriendCore.cpp @@ -678,12 +678,13 @@ void FriendCore::save() { // Save Values to model if (contact != nullptr) { auto friendModel = Utils::makeQObject_ptr(contact); friendModel->setSelf(friendModel); - mCoreModelConnection->invokeToCore([this, thisCopy, friendModel] { + mCoreModelConnection->invokeToCore([this, thisCopy, friendModel, contact] { mFriendModel = friendModel; - mCoreModelConnection->invokeToModel([this, thisCopy] { + mCoreModelConnection->invokeToModel([this, thisCopy, contact] { thisCopy->writeIntoModel(mFriendModel); thisCopy->deleteLater(); mVCardString = mFriendModel->getVCardAsString(); + emit CoreModel::getInstance()->friendUpdated(contact); mCoreModelConnection->invokeToCore([this] { setIsSaved(true); emit saved(); diff --git a/Linphone/model/friend/FriendsManager.cpp b/Linphone/model/friend/FriendsManager.cpp index e0b7f3bf3..72ea49fe4 100644 --- a/Linphone/model/friend/FriendsManager.cpp +++ b/Linphone/model/friend/FriendsManager.cpp @@ -29,6 +29,39 @@ DEFINE_ABSTRACT_OBJECT(FriendsManager) std::shared_ptr FriendsManager::gFriendsManager; FriendsManager::FriendsManager(QObject *parent) : QObject(parent) { moveToThread(CoreModel::getInstance()->thread()); + + connect(CoreModel::getInstance().get(), &CoreModel::friendRemoved, this, [this] (const std::shared_ptr &f) { + auto key = mKnownFriends.key(QVariant::fromValue(f), nullptr); + if (key != nullptr) { + mKnownFriends.remove(key); + } + auto unknown = mUnknownFriends.key(QVariant::fromValue(f), nullptr); + if (unknown != nullptr) { + mUnknownFriends.remove(unknown); + } + auto address = QString::fromStdString(f->getAddress()->asStringUriOnly()); + mOtherAddresses.removeAll(address); + }); + connect(CoreModel::getInstance().get(), &CoreModel::friendCreated, this, [this] (const std::shared_ptr &f) { + auto unknown = mUnknownFriends.key(QVariant::fromValue(f), nullptr); + if (unknown != nullptr) { + mUnknownFriends.remove(unknown); + } + auto address = QString::fromStdString(f->getAddress()->asStringUriOnly()); + mOtherAddresses.removeAll(address); + }); + connect(CoreModel::getInstance().get(), &CoreModel::friendUpdated, this, [this] (const std::shared_ptr &f) { + auto key = mKnownFriends.key(QVariant::fromValue(f), nullptr); + if (key != nullptr) { + mKnownFriends.remove(key); + } + auto unknown = mUnknownFriends.key(QVariant::fromValue(f), nullptr); + if (unknown != nullptr) { + mUnknownFriends.remove(unknown); + } + auto address = QString::fromStdString(f->getAddress()->asStringUriOnly()); + mOtherAddresses.removeAll(address); + }); } FriendsManager::~FriendsManager() { diff --git a/Linphone/model/friend/FriendsManager.hpp b/Linphone/model/friend/FriendsManager.hpp index c2656288d..5d42b1582 100644 --- a/Linphone/model/friend/FriendsManager.hpp +++ b/Linphone/model/friend/FriendsManager.hpp @@ -60,7 +60,6 @@ private: QVariantMap mKnownFriends; QVariantMap mUnknownFriends; QStringList mOtherAddresses; - //core model connection + reset unknown et other quand friend ajouté, supprimé, updated DECLARE_ABSTRACT_OBJECT };