diff --git a/Linphone/core/search/MagicSearchList.cpp b/Linphone/core/search/MagicSearchList.cpp index 750611108..b7c714caa 100644 --- a/Linphone/core/search/MagicSearchList.cpp +++ b/Linphone/core/search/MagicSearchList.cpp @@ -57,10 +57,13 @@ void MagicSearchList::setSelf(QSharedPointer me) { auto haveContact = std::find_if(mList.begin(), mList.end(), [friendCore](const QSharedPointer &item) { auto itemCore = item.objectCast(); + auto itemModel = itemCore->getFriendModel(); + auto friendModel = friendCore->getFriendModel(); return itemCore->getDefaultAddress().length() > 0 && itemCore->getDefaultAddress() == friendCore->getDefaultAddress() || - itemCore->getFriendModel() && friendCore->getFriendModel() && - itemCore->getFriendModel()->getFriend() == friendCore->getFriendModel()->getFriend(); + itemModel && friendModel && itemModel->getFriend() == friendModel->getFriend() && + itemModel->getFriend()->getFriendList()->getDisplayName() == + friendModel->getFriend()->getFriendList()->getDisplayName(); }); if (haveContact == mList.end()) { connect(friendCore.get(), &FriendCore::removed, this, qOverload(&MagicSearchList::remove)); @@ -118,19 +121,20 @@ void MagicSearchList::setSelf(QSharedPointer me) { address->asString())); // linphone Friend object remove specific address. contacts->append(contact); } else if (!it->getPhoneNumber().empty()) { - auto phoneNumber = it->getPhoneNumber(); + auto phoneNumber = it->getPhoneNumber(); linphoneFriend = CoreModel::getInstance()->getCore()->createFriend(); - linphoneFriend->addPhoneNumber(phoneNumber); + linphoneFriend->addPhoneNumber(phoneNumber); contact = FriendCore::create(linphoneFriend, isStored, it->getSourceFlags()); contact->setGivenName(Utils::coreStringToAppString(it->getPhoneNumber())); - contact->appendPhoneNumber(tr("device_id"), Utils::coreStringToAppString(it->getPhoneNumber())); + contact->appendPhoneNumber(tr("device_id"), + Utils::coreStringToAppString(it->getPhoneNumber())); contacts->append(contact); } } mModelConnection->invokeToCore([this, contacts]() { setResults(*contacts); delete contacts; - emit resultsProcessed(); + emit resultsProcessed(); }); }); qDebug() << log().arg("Initialized"); diff --git a/Linphone/model/search/MagicSearchModel.cpp b/Linphone/model/search/MagicSearchModel.cpp index cc3a713dc..580ba3f07 100644 --- a/Linphone/model/search/MagicSearchModel.cpp +++ b/Linphone/model/search/MagicSearchModel.cpp @@ -75,26 +75,43 @@ void MagicSearchModel::setMaxResults(int maxResults) { } } +bool isContactTemporary(std::shared_ptr f, bool allowNullFriendList = false) { + auto friendList = f ? f->getFriendList() : nullptr; + if (friendList == nullptr && !allowNullFriendList) return true; + return friendList && (friendList == ToolModel::getLdapFriendList()); +} + void MagicSearchModel::onSearchResultsReceived(const std::shared_ptr &magicSearch) { auto results = magicSearch->getLastSearch(); qDebug() << log().arg("SDK send callback: onSearchResultsReceived : %1 results.").arg(results.size()); auto appFriends = ToolModel::getAppFriendList(); auto ldapFriends = ToolModel::getLdapFriendList(); std::list> finalResults; - emit searchResultsReceived(results); + for (auto result : results) { + auto f = result->getFriend(); + bool isFromRemoteDirectory = result->hasSourceFlag(linphone::MagicSearch::Source::LdapServers) || + result->hasSourceFlag(linphone::MagicSearch::Source::RemoteCardDAV); + if (!isFromRemoteDirectory && isContactTemporary(f, true)) { + qDebug() << "Do not show friend " << f->getName() << "which is in a temporary friend list"; + continue; + } + finalResults.push_back(result); + } + emit searchResultsReceived(finalResults); for (auto result : results) { auto f = result->getFriend(); auto fList = f ? f->getFriendList() : nullptr; // qDebug() << log().arg("") << (f ? f->getName().c_str() : "NoFriend") << ", " // << (result->getAddress() ? result->getAddress()->asString().c_str() : "NoAddr") << " / " - // << (fList ? fList->getDisplayName().c_str() : "NoList") << result->getSourceFlags() << " / " + // << (fList ? fList->getDisplayName().c_str() : "NoList") << result->getSourceFlags() << " / + //" // << (f ? f.get() : nullptr); - bool isLdap = (result->getSourceFlags() & (int)linphone::MagicSearch::Source::LdapServers) != 0; // Do not add it into ldap_friends if it already exists in app_friends. - if (isLdap && f && (!fList || fList->getDisplayName() != "app_friends")) { // Double check because of SDK merging that lead to - // use a ldap result as of app_friends/ldap_friends. + if (isLdap && f && + (!fList || fList->getDisplayName() != "app_friends")) { // Double check because of SDK merging that lead to + // use a ldap result as of app_friends/ldap_friends. updateFriendListWithFriend(f, ldapFriends); } } @@ -134,5 +151,5 @@ void MagicSearchModel::updateFriendListWithFriend(const std::shared_ptraddFriend(linphoneFriend); - emit CoreModel::getInstance() -> friendCreated(linphoneFriend); + emit CoreModel::getInstance()->friendCreated(linphoneFriend); } diff --git a/Linphone/view/Control/Display/Contact/AllContactListView.qml b/Linphone/view/Control/Display/Contact/AllContactListView.qml index eabaeb640..b9dae99ac 100644 --- a/Linphone/view/Control/Display/Contact/AllContactListView.qml +++ b/Linphone/view/Control/Display/Contact/AllContactListView.qml @@ -63,8 +63,7 @@ Flickable { signal contactSelected(FriendGui contact) function selectContact(address) { - var index = contactsProxy.loadUntil( - address) // Be sure to have this address in proxy if it exists + var index = contactsProxy.loadUntil(address) // Be sure to have this address in proxy if it exists if (index != -1) { contactsList.selectIndex(index) } diff --git a/Linphone/view/Page/Main/Contact/ContactPage.qml b/Linphone/view/Page/Main/Contact/ContactPage.qml index 421610c50..0809a4c31 100644 --- a/Linphone/view/Page/Main/Contact/ContactPage.qml +++ b/Linphone/view/Page/Main/Contact/ContactPage.qml @@ -23,8 +23,7 @@ AbstractMainPage { property FriendGui selectedContact property string initialFriendToDisplay onInitialFriendToDisplayChanged: { - if (initialFriendToDisplay != '' && contactList.selectContact( - initialFriendToDisplay) != -1) + if (initialFriendToDisplay != '' && contactList.selectContact(initialFriendToDisplay) != -1) initialFriendToDisplay = "" else if (initialFriendToDisplay != '') console.warn("Abstract not selected yet: ", initialFriendToDisplay)