Commit cc33d9c2 authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

[ #13642 ] Better contact lookup

parent 15e64364
......@@ -86,14 +86,24 @@ ContactBackend* AkonadiBackend::getInstance()
///Find contact using a phone number
///@param resolveDNS check if the DNS is used by an account, then assume contact with that phone number / extension is the same as the caller
Contact* AkonadiBackend::getContactByPhone(const QString& phoneNumber,bool resolveDNS)
Contact* AkonadiBackend::getContactByPhone(const QString& phoneNumber,bool resolveDNS,Account* a)
{
if (!resolveDNS || phoneNumber.indexOf("@") == -1)
return m_ContactByPhone[phoneNumber];
else if (!getHostNameFromPhone(phoneNumber).isEmpty() && m_ContactByPhone[getUserFromPhone(phoneNumber)]) {
QString number = phoneNumber;
if (number.left(5) == "<sip:")
number = number.remove(0,5);
if (number.right(1) == ">")
number = number.remove(number.size()-1,1);
Contact* c = m_ContactByPhone[number];
if (c) {
return c;
}
else if (number.indexOf("@") == -1 && a)
return m_ContactByPhone[number+"@"+a->getAccountHostname()];
if (resolveDNS && number.indexOf("@") != -1 && !getHostNameFromPhone(number).isEmpty() && m_ContactByPhone[getUserFromPhone(number)]) {
foreach (Account* a, AccountList::getInstance()->getAccounts()) {
if (a->getAccountHostname() == getHostNameFromPhone(phoneNumber))
return m_ContactByPhone[getUserFromPhone(phoneNumber)];
if (a->getAccountHostname() == getHostNameFromPhone(number))
return m_ContactByPhone[getUserFromPhone(number)];
}
}
return nullptr;
......@@ -166,7 +176,12 @@ ContactList AkonadiBackend::update(Akonadi::Collection collection)
PhoneNumbers newNumbers;
foreach (KABC::PhoneNumber number, numbers) {
newNumbers << new Contact::PhoneNumber(number.number(),number.typeLabel());
m_ContactByPhone[number.number()] = aContact;
QString number2 = number.number();
if (number2.left(5) == "<sip:")
number2 = number2.remove(0,5);
if (number2.right(1) == ">")
number2 = number2.remove(number2.size()-1,1);
m_ContactByPhone[number2] = aContact;
}
m_ContactByUid[tmp.uid()] = aContact;
......
......@@ -50,15 +50,15 @@ class LIB_EXPORT AkonadiBackend : public ContactBackend {
Q_OBJECT
public:
static ContactBackend* getInstance();
Contact* getContactByPhone ( const QString& phoneNumber ,bool resolveDNS = false );
Contact* getContactByUid ( const QString& uid );
void editContact ( Contact* contact , QWidget* parent = 0 );
void addNewContact ( Contact* contact , QWidget* parent = 0 );
virtual void addPhoneNumber( Contact* contact , QString number, QString type );
Contact* getContactByPhone ( const QString& phoneNumber ,bool resolveDNS = false, Account* a=nullptr);
Contact* getContactByUid ( const QString& uid );
void editContact ( Contact* contact , QWidget* parent = 0 );
void addNewContact ( Contact* contact , QWidget* parent = 0 );
virtual void addPhoneNumber( Contact* contact , QString number, QString type );
virtual void editContact ( Contact* contact );
virtual void addNewContact ( Contact* contact );
virtual ~AkonadiBackend ( );
virtual void editContact ( Contact* contact );
virtual void addNewContact ( Contact* contact );
virtual ~AkonadiBackend ( );
private:
AkonadiBackend(QObject* parent);
......
......@@ -508,7 +508,7 @@ bool Call::isSecure() const {
Contact* Call::getContact()
{
if (!m_pContact && m_ContactChanged) {
m_pContact = m_pContactBackend->getContactByPhone(m_PeerPhoneNumber,true);
m_pContact = m_pContactBackend->getContactByPhone(m_PeerPhoneNumber,true,getAccount());
}
return m_pContact;
}
......
......@@ -301,19 +301,20 @@ CALLMODEL_TEMPLATE Call* CALLMODEL_T::addConference(const QString & confID)
return 0;
}
Call* newConf;
Call* newConf = nullptr;
if (m_sPrivateCallList_callId[callList[0]]->call_real->getAccount())
newConf = new Call(confID, m_sPrivateCallList_callId[callList[0]]->call_real->getAccount()->getAccountId());
InternalStruct* aNewStruct = new InternalStruct;
aNewStruct->call_real = newConf;
aNewStruct->conference = true;
m_sPrivateCallList_call[newConf] = aNewStruct;
m_sPrivateCallList_callId[confID] = aNewStruct;
if (newConf) {
InternalStruct* aNewStruct = new InternalStruct;
aNewStruct->call_real = newConf;
aNewStruct->conference = true;
m_lConfList[newConf->getConfId()] = newConf;
m_sPrivateCallList_call[newConf] = aNewStruct;
m_sPrivateCallList_callId[confID] = aNewStruct;
m_lConfList[newConf->getConfId()] = newConf;
}
return newConf;
} //addConference
......
......@@ -31,6 +31,7 @@
//SFLPhone
class Contact;
class Account;
//Typedef
typedef QList<Contact*> ContactList;
......@@ -44,7 +45,7 @@ public:
///Get a contact using a phone number
///@param resolveDNS interpret the number as is (false) or parse it to extract the domain and number (true)
virtual Contact* getContactByPhone ( const QString& phoneNumber , bool resolveDNS = false) = 0;
virtual Contact* getContactByPhone ( const QString& phoneNumber , bool resolveDNS = false, Account* a = nullptr) = 0;
///Return a contact (or nullptr) according to the contact unique identifier
virtual Contact* getContactByUid ( const QString& uid ) = 0;
......
Supports Markdown
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