do not display cached ldap friend if we are not doing ldap research

This commit is contained in:
Gaelle Braud 2025-04-01 10:16:17 +02:00
parent fb009fa17a
commit b607cac0d1
4 changed files with 35 additions and 16 deletions

View file

@ -57,10 +57,13 @@ void MagicSearchList::setSelf(QSharedPointer<MagicSearchList> me) {
auto haveContact = auto haveContact =
std::find_if(mList.begin(), mList.end(), [friendCore](const QSharedPointer<QObject> &item) { std::find_if(mList.begin(), mList.end(), [friendCore](const QSharedPointer<QObject> &item) {
auto itemCore = item.objectCast<FriendCore>(); auto itemCore = item.objectCast<FriendCore>();
auto itemModel = itemCore->getFriendModel();
auto friendModel = friendCore->getFriendModel();
return itemCore->getDefaultAddress().length() > 0 && return itemCore->getDefaultAddress().length() > 0 &&
itemCore->getDefaultAddress() == friendCore->getDefaultAddress() || itemCore->getDefaultAddress() == friendCore->getDefaultAddress() ||
itemCore->getFriendModel() && friendCore->getFriendModel() && itemModel && friendModel && itemModel->getFriend() == friendModel->getFriend() &&
itemCore->getFriendModel()->getFriend() == friendCore->getFriendModel()->getFriend(); itemModel->getFriend()->getFriendList()->getDisplayName() ==
friendModel->getFriend()->getFriendList()->getDisplayName();
}); });
if (haveContact == mList.end()) { if (haveContact == mList.end()) {
connect(friendCore.get(), &FriendCore::removed, this, qOverload<QObject *>(&MagicSearchList::remove)); connect(friendCore.get(), &FriendCore::removed, this, qOverload<QObject *>(&MagicSearchList::remove));
@ -118,19 +121,20 @@ void MagicSearchList::setSelf(QSharedPointer<MagicSearchList> me) {
address->asString())); // linphone Friend object remove specific address. address->asString())); // linphone Friend object remove specific address.
contacts->append(contact); contacts->append(contact);
} else if (!it->getPhoneNumber().empty()) { } else if (!it->getPhoneNumber().empty()) {
auto phoneNumber = it->getPhoneNumber(); auto phoneNumber = it->getPhoneNumber();
linphoneFriend = CoreModel::getInstance()->getCore()->createFriend(); linphoneFriend = CoreModel::getInstance()->getCore()->createFriend();
linphoneFriend->addPhoneNumber(phoneNumber); linphoneFriend->addPhoneNumber(phoneNumber);
contact = FriendCore::create(linphoneFriend, isStored, it->getSourceFlags()); contact = FriendCore::create(linphoneFriend, isStored, it->getSourceFlags());
contact->setGivenName(Utils::coreStringToAppString(it->getPhoneNumber())); 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); contacts->append(contact);
} }
} }
mModelConnection->invokeToCore([this, contacts]() { mModelConnection->invokeToCore([this, contacts]() {
setResults(*contacts); setResults(*contacts);
delete contacts; delete contacts;
emit resultsProcessed(); emit resultsProcessed();
}); });
}); });
qDebug() << log().arg("Initialized"); qDebug() << log().arg("Initialized");

View file

@ -75,26 +75,43 @@ void MagicSearchModel::setMaxResults(int maxResults) {
} }
} }
bool isContactTemporary(std::shared_ptr<linphone::Friend> 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<linphone::MagicSearch> &magicSearch) { void MagicSearchModel::onSearchResultsReceived(const std::shared_ptr<linphone::MagicSearch> &magicSearch) {
auto results = magicSearch->getLastSearch(); auto results = magicSearch->getLastSearch();
qDebug() << log().arg("SDK send callback: onSearchResultsReceived : %1 results.").arg(results.size()); qDebug() << log().arg("SDK send callback: onSearchResultsReceived : %1 results.").arg(results.size());
auto appFriends = ToolModel::getAppFriendList(); auto appFriends = ToolModel::getAppFriendList();
auto ldapFriends = ToolModel::getLdapFriendList(); auto ldapFriends = ToolModel::getLdapFriendList();
std::list<std::shared_ptr<linphone::SearchResult>> finalResults; std::list<std::shared_ptr<linphone::SearchResult>> 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) { for (auto result : results) {
auto f = result->getFriend(); auto f = result->getFriend();
auto fList = f ? f->getFriendList() : nullptr; auto fList = f ? f->getFriendList() : nullptr;
// qDebug() << log().arg("") << (f ? f->getName().c_str() : "NoFriend") << ", " // qDebug() << log().arg("") << (f ? f->getName().c_str() : "NoFriend") << ", "
// << (result->getAddress() ? result->getAddress()->asString().c_str() : "NoAddr") << " / " // << (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); // << (f ? f.get() : nullptr);
bool isLdap = (result->getSourceFlags() & (int)linphone::MagicSearch::Source::LdapServers) != 0; bool isLdap = (result->getSourceFlags() & (int)linphone::MagicSearch::Source::LdapServers) != 0;
// Do not add it into ldap_friends if it already exists in app_friends. // 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 if (isLdap && f &&
// use a ldap result as of app_friends/ldap_friends. (!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); updateFriendListWithFriend(f, ldapFriends);
} }
} }
@ -134,5 +151,5 @@ void MagicSearchModel::updateFriendListWithFriend(const std::shared_ptr<linphone
} }
qDebug() << log().arg("Adding Friend:") << linphoneFriend.get(); qDebug() << log().arg("Adding Friend:") << linphoneFriend.get();
friendList->addFriend(linphoneFriend); friendList->addFriend(linphoneFriend);
emit CoreModel::getInstance() -> friendCreated(linphoneFriend); emit CoreModel::getInstance()->friendCreated(linphoneFriend);
} }

View file

@ -63,8 +63,7 @@ Flickable {
signal contactSelected(FriendGui contact) signal contactSelected(FriendGui contact)
function selectContact(address) { function selectContact(address) {
var index = contactsProxy.loadUntil( var index = contactsProxy.loadUntil(address) // Be sure to have this address in proxy if it exists
address) // Be sure to have this address in proxy if it exists
if (index != -1) { if (index != -1) {
contactsList.selectIndex(index) contactsList.selectIndex(index)
} }

View file

@ -23,8 +23,7 @@ AbstractMainPage {
property FriendGui selectedContact property FriendGui selectedContact
property string initialFriendToDisplay property string initialFriendToDisplay
onInitialFriendToDisplayChanged: { onInitialFriendToDisplayChanged: {
if (initialFriendToDisplay != '' && contactList.selectContact( if (initialFriendToDisplay != '' && contactList.selectContact(initialFriendToDisplay) != -1)
initialFriendToDisplay) != -1)
initialFriendToDisplay = "" initialFriendToDisplay = ""
else if (initialFriendToDisplay != '') else if (initialFriendToDisplay != '')
console.warn("Abstract not selected yet: ", initialFriendToDisplay) console.warn("Abstract not selected yet: ", initialFriendToDisplay)