remove friend from friendsmanager maps when created, updated, removed

This commit is contained in:
gaelle 2025-04-16 16:26:00 +02:00
parent 8463c3e5f9
commit a2c0bfe558
3 changed files with 36 additions and 3 deletions

View file

@ -678,12 +678,13 @@ void FriendCore::save() { // Save Values to model
if (contact != nullptr) {
auto friendModel = Utils::makeQObject_ptr<FriendModel>(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();

View file

@ -29,6 +29,39 @@ DEFINE_ABSTRACT_OBJECT(FriendsManager)
std::shared_ptr<FriendsManager> FriendsManager::gFriendsManager;
FriendsManager::FriendsManager(QObject *parent) : QObject(parent) {
moveToThread(CoreModel::getInstance()->thread());
connect(CoreModel::getInstance().get(), &CoreModel::friendRemoved, this, [this] (const std::shared_ptr<linphone::Friend> &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<linphone::Friend> &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<linphone::Friend> &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() {

View file

@ -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
};