diff --git a/Linphone/core/call-history/CallHistoryCore.cpp b/Linphone/core/call-history/CallHistoryCore.cpp index d07ac379d..2e7f4c548 100644 --- a/Linphone/core/call-history/CallHistoryCore.cpp +++ b/Linphone/core/call-history/CallHistoryCore.cpp @@ -127,6 +127,16 @@ void CallHistoryCore::setSelf(QSharedPointer me) { mCoreModelConnection->makeConnectToModel(&CoreModel::friendCreated, update); mCoreModelConnection->makeConnectToModel(&CoreModel::friendUpdated, update); mCoreModelConnection->makeConnectToModel(&CoreModel::friendRemoved, &CallHistoryCore::onRemoved); + // Update display name when display name has been requested from magic search cause not found in linphone friends + // (required to get the right display name if ldap friends cleared) + mCoreModelConnection->makeConnectToModel(&CoreModel::magicSearchResultReceived, [this, remoteAddress = mRemoteAddress] { + auto displayName = ToolModel::getDisplayName(remoteAddress); + mCoreModelConnection->invokeToCore([this, displayName]() { + mDisplayName = displayName; + emit displayNameChanged(); + }); + }); + } ConferenceInfoGui *CallHistoryCore::getConferenceInfoGui() const { diff --git a/Linphone/core/participant/ParticipantDeviceCore.cpp b/Linphone/core/participant/ParticipantDeviceCore.cpp index 6a6301310..81c802bc3 100644 --- a/Linphone/core/participant/ParticipantDeviceCore.cpp +++ b/Linphone/core/participant/ParticipantDeviceCore.cpp @@ -44,7 +44,7 @@ ParticipantDeviceCore::ParticipantDeviceCore(const std::shared_ptrgetName()); - auto deviceAddress = device->getAddress(); + auto deviceAddress = device->getAddress()->clone(); mUniqueAddress = Utils::coreStringToAppString(deviceAddress->asString()); mAddress = Utils::coreStringToAppString(deviceAddress->asStringUriOnly()); // the display name of the device himself may be the uncleaned sip uri diff --git a/Linphone/model/conference/ConferenceInfoModel.cpp b/Linphone/model/conference/ConferenceInfoModel.cpp index 9a0632102..a8bbb92de 100644 --- a/Linphone/model/conference/ConferenceInfoModel.cpp +++ b/Linphone/model/conference/ConferenceInfoModel.cpp @@ -110,7 +110,7 @@ linphone::ConferenceInfo::State ConferenceInfoModel::getState() const { QString ConferenceInfoModel::getOrganizerName() const { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); - auto organizer = mConferenceInfo->getOrganizer(); + auto organizer = mConferenceInfo->getOrganizer()->clone(); auto name = Utils::coreStringToAppString(organizer->getDisplayName()); if (name.isEmpty()) name = ToolModel::getDisplayName(organizer); return name; diff --git a/Linphone/model/core/CoreModel.cpp b/Linphone/model/core/CoreModel.cpp index 3a75e1be0..7d44bfcd7 100644 --- a/Linphone/model/core/CoreModel.cpp +++ b/Linphone/model/core/CoreModel.cpp @@ -118,6 +118,14 @@ void CoreModel::start() { if (mCore->getLogCollectionUploadServerUrl().empty()) mCore->setLogCollectionUploadServerUrl(Constants::DefaultUploadLogsServer); mIterateTimer->start(); + + auto linphoneSearch = mCore->createMagicSearch(); + linphoneSearch->setLimitedSearch(true); + mMagicSearch = Utils::makeQObject_ptr(linphoneSearch); + mMagicSearch->setSelf(mMagicSearch); + connect(mMagicSearch.get(), &MagicSearchModel::searchResultsReceived, this, [this] { + emit magicSearchResultReceived(mMagicSearch->mLastSearch); + }); } // ----------------------------------------------------------------------------- @@ -345,6 +353,12 @@ void CoreModel::migrate() { config->setInt(SettingsModel::UiSection, Constants::RcVersionName, Constants::RcVersionCurrent); } +void CoreModel::searchInMagicSearch(QString filter, int sourceFlags, + LinphoneEnums::MagicSearchAggregation aggregation, + int maxResults) { + mMagicSearch->search(filter, sourceFlags, aggregation, maxResults); +} + //--------------------------------------------------------------------------------------------------------------------------- void CoreModel::onAccountAdded(const std::shared_ptr &core, diff --git a/Linphone/model/core/CoreModel.hpp b/Linphone/model/core/CoreModel.hpp index 4aa6e61be..af6da1a09 100644 --- a/Linphone/model/core/CoreModel.hpp +++ b/Linphone/model/core/CoreModel.hpp @@ -35,6 +35,7 @@ #include "model/listener/Listener.hpp" #include "model/logger/LoggerModel.hpp" #include "tool/AbstractObject.hpp" +#include "model/search/MagicSearchModel.hpp" // ============================================================================= @@ -59,6 +60,11 @@ public: bool setFetchConfig(QString filePath); void migrate(); + void searchInMagicSearch(QString filter, + int sourceFlags, + LinphoneEnums::MagicSearchAggregation aggregation, + int maxResults); + bool mEnd = false; std::shared_ptr mCore; @@ -75,11 +81,13 @@ signals: void requestFetchConfig(QString path); void requestRestart(); void enabledLdapAddressBookSaved(); + void magicSearchResultReceived(QString filter); private: QString mConfigPath; QTimer *mIterateTimer = nullptr; QMap mOpenIdConnections; + std::shared_ptr mMagicSearch; void setPathBeforeCreation(); void setPathsAfterCreation(); diff --git a/Linphone/model/object/VariantObject.cpp b/Linphone/model/object/VariantObject.cpp index 33874b416..c058bde53 100644 --- a/Linphone/model/object/VariantObject.cpp +++ b/Linphone/model/object/VariantObject.cpp @@ -77,5 +77,5 @@ void VariantObject::setDefaultValue(QVariant value) { mCoreObject->setDefaultValue(value); } void VariantObject::requestValue() { - emit mCoreObject->requestValue(); + if (mCoreObject) emit mCoreObject->requestValue(); } diff --git a/Linphone/model/tool/ToolModel.cpp b/Linphone/model/tool/ToolModel.cpp index 2385a00f9..e83a6ce92 100644 --- a/Linphone/model/tool/ToolModel.cpp +++ b/Linphone/model/tool/ToolModel.cpp @@ -78,10 +78,10 @@ std::shared_ptr ToolModel::findAudioDevice(const QString return nullptr; } -QString ToolModel::getDisplayName(const std::shared_ptr &address) { +QString ToolModel::getDisplayName(const std::shared_ptr &address) { QString displayName; if (address) { - auto linFriend = CoreModel::getInstance()->getCore()->findFriend(address); + auto linFriend = ToolModel::findFriendByAddress(address); if (linFriend) { if (displayName.isEmpty()) displayName = Utils::coreStringToAppString(linFriend->getName()); } @@ -119,11 +119,22 @@ std::shared_ptr ToolModel::findFriendByAddress(const QString & auto defaultFriendList = CoreModel::getInstance()->getCore()->getDefaultFriendList(); if (!defaultFriendList) return nullptr; auto linphoneAddr = ToolModel::interpretUrl(address); - return CoreModel::getInstance()->getCore()->findFriend(linphoneAddr); + if (linphoneAddr) + return ToolModel::findFriendByAddress(linphoneAddr); + else + return nullptr; } std::shared_ptr ToolModel::findFriendByAddress(std::shared_ptr linphoneAddr) { - return CoreModel::getInstance()->getCore()->findFriend(linphoneAddr); + auto f = CoreModel::getInstance()->getCore()->findFriend(linphoneAddr); + if (!f) { + qDebug() << "Couldn't find friend" << linphoneAddr->asStringUriOnly() << "in core, use magic search"; + CoreModel::getInstance()->searchInMagicSearch(Utils::coreStringToAppString(linphoneAddr->asStringUriOnly()), + (int)linphone::MagicSearch::Source::LdapServers + | (int)linphone::MagicSearch::Source::RemoteCardDAV + , LinphoneEnums::MagicSearchAggregation::Friend, 50); + } + return f; } bool ToolModel::createCall(const QString &sipAddress, diff --git a/Linphone/model/tool/ToolModel.hpp b/Linphone/model/tool/ToolModel.hpp index 9fdf69918..bc35cd70f 100644 --- a/Linphone/model/tool/ToolModel.hpp +++ b/Linphone/model/tool/ToolModel.hpp @@ -47,7 +47,7 @@ public: static bool isLocal(const std::shared_ptr &conference, const std::shared_ptr &device); - static QString getDisplayName(const std::shared_ptr &address); + static QString getDisplayName(const std::shared_ptr &address); static QString getDisplayName(QString address); static std::shared_ptr findFriendByAddress(const QString &address); diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index 15775ceae..786b71c51 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -225,6 +225,8 @@ VariantObject *Utils::haveAccount() { return CoreModel::getInstance()->getCore()->getAccountList().size() > 0; }); result->makeUpdate(CoreModel::getInstance().get(), &CoreModel::accountAdded); + result->makeUpdate(CoreModel::getInstance().get(), &CoreModel::accountRemoved); + result->requestValue(); return result; } @@ -418,6 +420,7 @@ VariantObject *Utils::findFriendByAddress(const QString &address) { }; data->makeUpdateCond(CoreModel::getInstance().get(), &CoreModel::friendCreated, updateValue); // New Friend data->makeUpdateCond(CoreModel::getInstance().get(), &CoreModel::friendRemoved, updateValue); // New Friend + data->makeUpdateCond(CoreModel::getInstance().get(), &CoreModel::friendUpdated, updateValue); data->requestValue(); return data; } diff --git a/Linphone/view/Control/Display/Call/CallHistoryListView.qml b/Linphone/view/Control/Display/Call/CallHistoryListView.qml index 2aa557cf8..088b81996 100644 --- a/Linphone/view/Control/Display/Call/CallHistoryListView.qml +++ b/Linphone/view/Control/Display/Call/CallHistoryListView.qml @@ -104,8 +104,8 @@ ListView { //---------------------------------------------------------------- onVisibleChanged: { - if (!visible) - currentIndex = -1 +// if (!visible) +// currentIndex = -1 } BusyIndicator {