Commit 01cb565e authored by Erwan Croze's avatar Erwan Croze 👋🏻
Browse files

Adding phone number to search result

parent 20e45ee0
......@@ -51,6 +51,11 @@ LINPHONE_PUBLIC const LinphoneFriend* linphone_search_result_get_friend(const Li
**/
LINPHONE_PUBLIC const LinphoneAddress* linphone_search_result_get_address(const LinphoneSearchResult *searchResult);
/**
* @return Phone Number associed
**/
LINPHONE_PUBLIC const char* linphone_search_result_get_phone_number(const LinphoneSearchResult *searchResult);
/**
* @return the result weight
**/
......
......@@ -39,6 +39,10 @@ const LinphoneAddress* linphone_search_result_get_address(const LinphoneSearchRe
return L_GET_CPP_PTR_FROM_C_OBJECT(searchResult)->getAddress();
}
const char* linphone_search_result_get_phone_number(const LinphoneSearchResult *searchResult) {
return L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(searchResult)->getPhoneNumber());
}
unsigned int linphone_search_result_get_weight(const LinphoneSearchResult *searchResult) {
return L_GET_CPP_PTR_FROM_C_OBJECT(searchResult)->getWeight();
}
......@@ -26,6 +26,7 @@
#include "linphone/utils/utils.h"
#include "linphone/core.h"
#include "linphone/types.h"
#include "logger/logger.h"
#include "private.h"
using namespace std;
......@@ -149,7 +150,7 @@ list<SearchResult> MagicSearch::getContactListFromFilter(const string &filter, c
if (domain) {
string filterAddress = "sip:" + filter + "@" + domain;
LinphoneAddress *lastResult = linphone_core_create_address(this->getCore()->getCCore(), filterAddress.c_str());
if (lastResult) returnList.push_back(SearchResult(0, lastResult, nullptr));
if (lastResult) returnList.push_back(SearchResult(0, lastResult, "", nullptr));
}
}
......@@ -178,9 +179,11 @@ list<SearchResult> MagicSearch::getAllFriends() {
for (bctbx_list_t *f = list->friends ; f != nullptr ; f = bctbx_list_next(f)) {
const LinphoneFriend *lFriend = reinterpret_cast<LinphoneFriend*>(f->data);
const LinphoneAddress* lAddress = linphone_friend_get_address(lFriend);
bctbx_list_t *lPhoneNumbers = linphone_friend_get_phone_numbers(lFriend);
string lPhoneNumber = (lPhoneNumbers != nullptr) ? static_cast<const char*>(lPhoneNumbers->data) : "";
if (lAddress) linphone_address_ref(const_cast<LinphoneAddress *>(lAddress));
returnList.push_back(SearchResult(1, lAddress, lFriend));
returnList.push_back(SearchResult(1, lAddress, lPhoneNumber, lFriend));
}
return returnList;
......@@ -195,7 +198,9 @@ list<SearchResult> *MagicSearch::beginNewSearch(const string &filter, const stri
for (bctbx_list_t *f = list->friends ; f != nullptr ; f = bctbx_list_next(f)) {
SearchResult result = searchInFriend(reinterpret_cast<LinphoneFriend*>(f->data), filter, withDomain);
if (result.getWeight() > getMinWeight()) {
resultList->push_back(result);
if (result.getAddress() || !result.getPhoneNumber().empty()) {
resultList->push_back(result);
}
}
}
......@@ -209,7 +214,7 @@ list<SearchResult> *MagicSearch::beginNewSearch(const string &filter, const stri
if (weight > getMinWeight()) {
// FIXME: Ugly temporary workaround to solve weak. Remove me later.
linphone_address_ref(const_cast<LinphoneAddress *>(addr));
resultList->push_back(SearchResult(weight, addr, nullptr));
resultList->push_back(SearchResult(weight, addr, "", nullptr));
}
}
}
......@@ -222,10 +227,17 @@ list<SearchResult> *MagicSearch::continueSearch(const string &filter, const stri
const list <SearchResult> *cacheList = getSearchCache();
for (const auto sr : *cacheList) {
if (sr.getFriend()) {
SearchResult result = searchInFriend(sr.getFriend(), filter, withDomain);
if (result.getWeight() > getMinWeight()) {
resultList->push_back(result);
if (sr.getAddress() || !sr.getPhoneNumber().empty()) {
if (sr.getFriend()) {
SearchResult result = searchInFriend(sr.getFriend(), filter, withDomain);
if (result.getWeight() > getMinWeight()) {
resultList->push_back(result);
}
} else {
unsigned int weight = searchInAddress(sr.getAddress(), filter, withDomain);
if (weight > getMinWeight()) {
resultList->push_back(SearchResult(weight, sr.getAddress(), sr.getPhoneNumber(), nullptr));
}
}
}
}
......@@ -234,11 +246,12 @@ list<SearchResult> *MagicSearch::continueSearch(const string &filter, const stri
}
SearchResult MagicSearch::searchInFriend(const LinphoneFriend *lFriend, const string &filter, const string &withDomain) {
string phoneNumber = "";
unsigned int weight = getMinWeight();
const LinphoneAddress* lAddress = linphone_friend_get_address(lFriend);
if (!checkDomain(lFriend, lAddress, withDomain)) {
if (!withDomain.empty()) return SearchResult(weight, nullptr);
if (!withDomain.empty()) return SearchResult(weight, nullptr, "");
}
// NAME
......@@ -252,12 +265,17 @@ SearchResult MagicSearch::searchInFriend(const LinphoneFriend *lFriend, const st
weight += searchInAddress(lAddress, filter, withDomain) * 1;
// PHONE NUMBER
LinphoneProxyConfig *proxy = linphone_core_get_default_proxy_config(this->getCore()->getCCore());
bctbx_list_t *begin, *phoneNumbers = linphone_friend_get_phone_numbers(lFriend);
begin = phoneNumbers;
while (phoneNumbers && phoneNumbers->data) {
string number = static_cast<const char*>(phoneNumbers->data);
const LinphonePresenceModel *presence = linphone_friend_get_presence_model_for_uri_or_tel(lFriend, number.c_str());
weight += getWeight(number, filter);
phoneNumber = number;
if (proxy) {
phoneNumber = linphone_proxy_config_normalize_phone_number(proxy, phoneNumber.c_str());
}
weight += getWeight(phoneNumber.c_str(), filter);
if (presence) {
char *contact = linphone_presence_model_get_contact(presence);
weight += getWeight(contact, filter) * 2;
......@@ -269,7 +287,7 @@ SearchResult MagicSearch::searchInFriend(const LinphoneFriend *lFriend, const st
// FIXME: Ugly temporary workaround to solve weak. Remove me later.
if (lAddress) linphone_address_ref(const_cast<LinphoneAddress *>(lAddress));
return SearchResult(weight, lAddress, lFriend);
return SearchResult(weight, lAddress, phoneNumber, lFriend);
}
unsigned int MagicSearch::searchInAddress(const LinphoneAddress *lAddress, const string &filter, const string &withDomain) {
......@@ -328,7 +346,7 @@ unsigned int MagicSearch::getWeight(const string &stringWords, const string &fil
return (weight != string::npos) ? (unsigned int)(weight) : getMinWeight();
}
bool MagicSearch::checkDomain (const LinphoneFriend *lFriend, const LinphoneAddress *lAddress, const string &withDomain) const {
bool MagicSearch::checkDomain(const LinphoneFriend *lFriend, const LinphoneAddress *lAddress, const string &withDomain) const {
bool onlySipUri = !withDomain.empty() && withDomain.compare("*") != 0;
const LinphonePresenceModel *presenceModel = lFriend ? linphone_friend_get_presence_model(lFriend) : nullptr;
char *contactPresence = presenceModel ? linphone_presence_model_get_contact(presenceModel) : nullptr;
......
......@@ -30,59 +30,69 @@ class SearchResultPrivate : public ClonableObjectPrivate {
private:
const LinphoneFriend *mFriend;
const LinphoneAddress *mAddress;
std::string mPhoneNumber;
unsigned int mWeight;
L_DECLARE_PUBLIC(SearchResult);
};
SearchResult::SearchResult (const unsigned int weight, const LinphoneAddress *a, const LinphoneFriend *f) : ClonableObject(*new SearchResultPrivate) {
using namespace std;
SearchResult::SearchResult(const unsigned int weight, const LinphoneAddress *a, const string &pn, const LinphoneFriend *f) : ClonableObject(*new SearchResultPrivate) {
L_D();
d->mWeight = weight;
d->mAddress = a;
d->mFriend = f;
d->mPhoneNumber = pn;
}
SearchResult::SearchResult (const SearchResult &sr) : ClonableObject(*new SearchResultPrivate) {
SearchResult::SearchResult(const SearchResult &sr) : ClonableObject(*new SearchResultPrivate) {
L_D();
d->mWeight = sr.getWeight();
d->mAddress = sr.getAddress();
if (d->mAddress) linphone_address_ref(const_cast<LinphoneAddress *>(d->mAddress));
d->mFriend = sr.getFriend();
d->mPhoneNumber = sr.getPhoneNumber();
}
SearchResult::~SearchResult () {
SearchResult::~SearchResult() {
L_D();
// FIXME: Ugly temporary workaround to solve weak. Remove me later.
if (d->mAddress) linphone_address_unref(const_cast<LinphoneAddress *>(d->mAddress));
};
bool SearchResult::operator< (const SearchResult &other) const {
bool SearchResult::operator<(const SearchResult &other) const {
return getWeight() < other.getWeight();
}
bool SearchResult::operator> (const SearchResult &other) const {
bool SearchResult::operator>(const SearchResult &other) const {
return getWeight() > other.getWeight();
}
bool SearchResult::operator>= (const SearchResult &other) const {
bool SearchResult::operator>=(const SearchResult &other) const {
return getWeight() >= other.getWeight();
}
bool SearchResult::operator= (const SearchResult &other) const {
bool SearchResult::operator=(const SearchResult &other) const {
return getWeight() == other.getWeight();
}
const LinphoneFriend *SearchResult::getFriend () const {
const LinphoneFriend *SearchResult::getFriend() const {
L_D();
return d->mFriend;
}
const LinphoneAddress *SearchResult::getAddress () const {
const LinphoneAddress *SearchResult::getAddress() const {
L_D();
return d->mAddress;
}
unsigned int SearchResult::getWeight () const {
const string &SearchResult::getPhoneNumber() const {
L_D();
return d->mPhoneNumber;
}
unsigned int SearchResult::getWeight() const {
L_D();
return d->mWeight;
}
......
......@@ -34,29 +34,34 @@ class SearchResultPrivate;
class LINPHONE_PUBLIC SearchResult : public ClonableObject {
public:
// TODO: Use C++ Address! Not LinphoneAddress.
SearchResult (const unsigned int weight, const LinphoneAddress *a, const LinphoneFriend *f = nullptr);
SearchResult (const SearchResult &other);
~SearchResult ();
SearchResult(const unsigned int weight, const LinphoneAddress *a, const std::string &pn, const LinphoneFriend *f = nullptr);
SearchResult(const SearchResult &other);
~SearchResult();
bool operator< (const SearchResult &other) const;
bool operator> (const SearchResult &other) const;
bool operator>= (const SearchResult &other) const;
bool operator= (const SearchResult &other) const;
bool operator<(const SearchResult &other) const;
bool operator>(const SearchResult &other) const;
bool operator>=(const SearchResult &other) const;
bool operator=(const SearchResult &other) const;
/**
* @return LinphoneFriend associed
**/
const LinphoneFriend *getFriend() const;
const LinphoneFriend *getFriend()const;
/**
* @return LinphoneAddress associed
**/
const LinphoneAddress *getAddress () const;
const LinphoneAddress *getAddress() const;
/**
* @return Phone Number associed
**/
const std::string &getPhoneNumber() const;
/**
* @return the result weight
**/
unsigned int getWeight () const;
unsigned int getWeight() const;
private:
L_DECLARE_PRIVATE(SearchResult);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment