Skip to content
Snippets Groups Projects
Commit 452317eb authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

[ #54786 ] Add more comments to the getNumber() algo

Those future improvments were raised during a code review
parent 1db25f07
Branches
Tags
No related merge requests found
......@@ -324,10 +324,11 @@ PhoneNumber* PhoneDirectoryModel::getNumber(const QString& uri, Account* account
}
///Add new information to existing numbers and try to merge
PhoneNumber* PhoneDirectoryModel::fillDetails(NumberWrapper* wrap, const URI& strippedUri, Account* account, Contact* contact, const QString& type,bool& hasContact)
PhoneNumber* PhoneDirectoryModel::fillDetails(NumberWrapper* wrap, const URI& strippedUri, Account* account, Contact* contact, const QString& type)
{
//TODO pick the best URI
//TODO the account hostname change corner case
//TODO search for account that has the same hostname as the URI
if (wrap) {
foreach(PhoneNumber* number, wrap->numbers) {
......@@ -364,6 +365,8 @@ PhoneNumber* PhoneDirectoryModel::fillDetails(NumberWrapper* wrap, const URI& st
));
//TODO the Display name could be used to influence the choice
//It would need to ignore all possible translated values of unknown
//and only be available when another information match
//If everything match, set the contact
if (hasCompatibleAccount)
......@@ -385,8 +388,6 @@ PhoneNumber* PhoneDirectoryModel::fillDetails(NumberWrapper* wrap, const URI& st
number->setCategory(NumberCategoryModel::instance()->getCategory(type));
}
hasContact |= number->contact()!= nullptr;
//We already have enough information to confirm the choice
if (contact && number->contact() &&((contact->uid()) == number->contact()->uid()))
return number;
......@@ -432,12 +433,9 @@ PhoneNumber* PhoneDirectoryModel::getNumber(const QString& uri, const QString& t
///Create a number when a more information is available duplicated ones
PhoneNumber* PhoneDirectoryModel::getNumber(const QString& uri, Contact* contact, Account* account, const QString& type)
{
//Remove extra data such as "<sip:" from the main URI
const URI strippedUri(uri);
//Try to use a PhoneNumber with a contact when possible, work only after the
//contact are loaded
bool hasContact(false),hasContact2(false);
//See if the number is already loaded
NumberWrapper* wrap = m_hDirectory[strippedUri];
NumberWrapper* wrap2 = nullptr;
......@@ -452,13 +450,16 @@ PhoneNumber* PhoneDirectoryModel::getNumber(const QString& uri, Contact* contact
}
//Check
PhoneNumber* confirmedCandidate = fillDetails(wrap,strippedUri,account,contact,type,hasContact);
PhoneNumber* confirmedCandidate = fillDetails(wrap,strippedUri,account,contact,type);
//URIs can be represented in multiple way, check if a more verbose version
//already exist
PhoneNumber* confirmedCandidate2 = nullptr;
if (!hasContact)
confirmedCandidate2 = fillDetails(wrap2,strippedUri,account,contact,type,hasContact2);
//Try to use a PhoneNumber with a contact when possible, work only after the
//contact are loaded
if (confirmedCandidate && confirmedCandidate->contact())
confirmedCandidate2 = fillDetails(wrap2,strippedUri,account,contact,type);
PhoneNumber* confirmedCandidate3 = nullptr;
......@@ -492,7 +493,8 @@ PhoneNumber* PhoneDirectoryModel::getNumber(const QString& uri, Contact* contact
confirmedCandidate->merge(confirmedCandidate2);
}
//Empirical testing resulted in this as the best return order
//The merge may have failed either in the "if" above or in the merging code
if (confirmedCandidate2)
return confirmedCandidate2;
if (confirmedCandidate)
......@@ -504,6 +506,8 @@ PhoneNumber* PhoneDirectoryModel::getNumber(const QString& uri, Contact* contact
if (wrap) {
foreach(PhoneNumber* number, wrap->numbers) {
if (((!account) || number->account() == account) && ((!contact) || ((*contact) == number->contact()) || (!number->contact()))) {
//Assume this is valid until a smarter solution is implemented to merge both
//For a short time, a placeholder contact and a contact can coexist, drop the placeholder
if (contact && (!number->contact() || (contact->uid() == number->contact()->uid())))
number->setContact(contact);
......
......@@ -117,7 +117,7 @@ private:
//Helpers
void indexNumber(PhoneNumber* number, const QStringList& names );
void setAccount (PhoneNumber* number, Account* account );
PhoneNumber* fillDetails(NumberWrapper* wrap, const URI& strippedUri, Account* account, Contact* contact, const QString& type, bool& hasContact);
PhoneNumber* fillDetails(NumberWrapper* wrap, const URI& strippedUri, Account* account, Contact* contact, const QString& type);
//Singleton
static PhoneDirectoryModel* m_spInstance;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment