do not display cached ldap friend if we are not doing ldap research
This commit is contained in:
parent
fb009fa17a
commit
b607cac0d1
4 changed files with 35 additions and 16 deletions
|
|
@ -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));
|
||||||
|
|
@ -123,7 +126,8 @@ void MagicSearchList::setSelf(QSharedPointer<MagicSearchList> me) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,25 +75,42 @@ 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 &&
|
||||||
|
(!fList || fList->getDisplayName() != "app_friends")) { // Double check because of SDK merging that lead to
|
||||||
// use a ldap result as of app_friends/ldap_friends.
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue