diff --git a/Linphone/core/participant/ParticipantCore.cpp b/Linphone/core/participant/ParticipantCore.cpp index 04d22c5e5..3accf5ac0 100644 --- a/Linphone/core/participant/ParticipantCore.cpp +++ b/Linphone/core/participant/ParticipantCore.cpp @@ -20,10 +20,8 @@ #include -#include "core/App.hpp" - #include "ParticipantCore.hpp" -// #include "ParticipantDeviceList.hpp" +#include "core/App.hpp" #include "model/participant/ParticipantModel.hpp" #include "model/tool/ToolModel.hpp" #include "tool/Utils.hpp" @@ -77,6 +75,48 @@ void ParticipantCore::setSelf(QSharedPointer me) { QTimer::singleShot(secs * 1000, this, &ParticipantCore::onEndOfInvitation); }); connect(this, &ParticipantCore::sipAddressChanged, this, &ParticipantCore::updateIsMe); + auto update = [this, remoteAddress = mSipAddress](const std::shared_ptr &updatedFriend) { + bool isThisFriend = false; + std::shared_ptr friendAddress; + auto participantAddress = mParticipantModel->getAddress(); + for (auto address : updatedFriend->getAddresses()) { + if (address->weakEqual(participantAddress)) { + isThisFriend = true; + friendAddress = address; + break; + } + } + if (isThisFriend) { + auto displayName = friendAddress->getDisplayName(); + mCoreModelConnection->invokeToCore([this, displayName] { + auto me = mCoreModelConnection->mCore.mQData; // Locked from previous call. + setDisplayName(Utils::coreStringToAppString(displayName)); + }); + } + }; + auto onRemoved = [this](const std::shared_ptr &updatedFriend) { + bool isThisFriend = false; + std::shared_ptr friendAddress; + auto participantAddress = mParticipantModel->getAddress(); + for (auto address : updatedFriend->getAddresses()) { + if (address->weakEqual(participantAddress)) { + isThisFriend = true; + friendAddress = address; + break; + } + } + if (isThisFriend) { + auto displayName = ToolModel::getDisplayName(participantAddress); + mCoreModelConnection->invokeToCore([this, displayName] { + auto me = mCoreModelConnection->mCore.mQData; // Locked from previous call. + setDisplayName(displayName); + }); + } + }; + mCoreModelConnection = SafeConnection::create(me, CoreModel::getInstance()); + mCoreModelConnection->makeConnectToModel(&CoreModel::friendCreated, update); + mCoreModelConnection->makeConnectToModel(&CoreModel::friendUpdated, update); + mCoreModelConnection->makeConnectToModel(&CoreModel::friendRemoved, onRemoved); } LinphoneEnums::SecurityLevel ParticipantCore::getSecurityLevel() const { diff --git a/Linphone/core/participant/ParticipantCore.hpp b/Linphone/core/participant/ParticipantCore.hpp index 2daf6101c..275cae001 100644 --- a/Linphone/core/participant/ParticipantCore.hpp +++ b/Linphone/core/participant/ParticipantCore.hpp @@ -107,6 +107,7 @@ signals: private: std::shared_ptr mParticipantModel; QSharedPointer> mParticipantConnection; + QSharedPointer> mCoreModelConnection; QList mParticipantDevices; diff --git a/Linphone/model/participant/ParticipantModel.cpp b/Linphone/model/participant/ParticipantModel.cpp index 9a7e77d5e..53bbca859 100644 --- a/Linphone/model/participant/ParticipantModel.cpp +++ b/Linphone/model/participant/ParticipantModel.cpp @@ -52,6 +52,10 @@ QString ParticipantModel::getSipAddress() const { return Utils::coreStringToAppString(mParticipant->getAddress()->asString()); } +std::shared_ptr ParticipantModel::getAddress() const { + return mParticipant ? mParticipant->getAddress() : nullptr; +} + QDateTime ParticipantModel::getCreationTime() const { return QDateTime::fromSecsSinceEpoch(mParticipant->getCreationTime()); } diff --git a/Linphone/model/participant/ParticipantModel.hpp b/Linphone/model/participant/ParticipantModel.hpp index ac1a8329c..4ceec6047 100644 --- a/Linphone/model/participant/ParticipantModel.hpp +++ b/Linphone/model/participant/ParticipantModel.hpp @@ -40,6 +40,7 @@ public: ~ParticipantModel(); QString getSipAddress() const; + std::shared_ptr getAddress() const; QDateTime getCreationTime() const; bool getAdminStatus() const; bool isFocus() const;