Skip to content

Commit

Permalink
Fix ldap results: do not synchronized ldap list if already exist in l…
Browse files Browse the repository at this point in the history
…ocal to avoid losing data on SDK merge.

Prioritize app_friends list in results.
Update SDK.
  • Loading branch information
Ledjlale committed Nov 28, 2024
1 parent d24a68e commit 0b193de
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Linphone/core/search/MagicSearchProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ bool MagicSearchProxy::SortFilterList::filterAcceptsRow(int sourceRow, const QMo
// if (!toShow) return false;
}
if (!toShow && (mFilterType & (int)FilteringTypes::App) > 0) {
toShow = friendCore->getIsStored();
toShow = friendCore->getIsStored() && !friendCore->isLdap();
// if (!toShow) return false;
}
if (!toShow && (mFilterType & (int)FilteringTypes::Other) > 0) {
Expand Down
41 changes: 27 additions & 14 deletions Linphone/model/search/MagicSearchModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,34 @@ void MagicSearchModel::setMaxResults(int maxResults) {
}

void MagicSearchModel::onSearchResultsReceived(const std::shared_ptr<linphone::MagicSearch> &magicSearch) {
qDebug() << log().arg("SDK send callback: onSearchResultsReceived");
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<std::shared_ptr<linphone::SearchResult>> finalResults;
for (auto it : results) {
bool isLdap = (it->getSourceFlags() & (int)LinphoneEnums::MagicSearchSource::LdapServers) != 0;
bool toAdd = true;
if (isLdap && it->getFriend()) {
updateLdapFriendListWithFriend(it->getFriend());
if (appFriends->findFriendByAddress(it->getFriend()->getAddress())) { // Already exist in app list
toAdd = false;
}
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() << " / "
<< (f ? f.get() : nullptr);

bool isLdap = (result->getSourceFlags() & (int)LinphoneEnums::MagicSearchSource::LdapServers) != 0;
// Do not add it into ldap_friends if it already exists in app_friends.
if (isLdap && f && (!fList || fList->getDisplayName() != "app_friends") &&
!ToolModel::friendIsInFriendList(appFriends, f)) { // Double check because of SDK merging that lead to
// use a ldap result as of app_friends/ldap_friends.
updateLdapFriendListWithFriend(f);
}
if (toAdd &&
std::find_if(finalResults.begin(), finalResults.end(), [it](std::shared_ptr<linphone::SearchResult> r) {
return r->getAddress()->weakEqual(it->getAddress());
}) == finalResults.end())
finalResults.push_back(it);

auto resultIt =
std::find_if(finalResults.begin(), finalResults.end(), [result](std::shared_ptr<linphone::SearchResult> r) {
return r->getAddress()->weakEqual(result->getAddress());
});
if (resultIt == finalResults.end()) finalResults.push_back(result);
else if (fList && fList->getDisplayName() == "app_friends") *resultIt = result; // replace if local friend
}
emit searchResultsReceived(finalResults);
}
Expand All @@ -110,6 +120,8 @@ void MagicSearchModel::updateLdapFriendListWithFriend(const std::shared_ptr<linp
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
auto core = CoreModel::getInstance()->getCore();
auto ldapFriendList = ToolModel::getLdapFriendList();
if (ToolModel::friendIsInFriendList(ldapFriendList, linphoneFriend))
return; // Already exist. We don't need to manipulate list.
for (auto address : linphoneFriend->getAddresses()) {
auto existingFriend = ldapFriendList->findFriendByAddress(address);
if (existingFriend) {
Expand All @@ -126,6 +138,7 @@ void MagicSearchModel::updateLdapFriendListWithFriend(const std::shared_ptr<linp
return;
}
}
qDebug() << log().arg("Adding Friend:") << linphoneFriend.get();
ldapFriendList->addFriend(linphoneFriend);
emit CoreModel::getInstance()->friendCreated(linphoneFriend);
}
2 changes: 1 addition & 1 deletion external/linphone-sdk
Submodule linphone-sdk updated from b9b42a to bc6747

0 comments on commit 0b193de

Please sign in to comment.