diff --git a/src/person.cpp b/src/person.cpp index f2dee319039666e7ef0532093d49ec156a4b57b5..c127629cea120e4dfab9b1246883105115654469 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -193,19 +193,6 @@ void PersonPrivate::registerContactMethod(ContactMethod* m) slotLastUsedTimeChanged(m->lastUsed()); } -/** - * @return the best Id for the last ContactMethod used with that person. - */ -QString -PersonPrivate::getLastIdUsed() -{ - auto lastPhoneNumberUsed = std::max_element(m_Numbers.begin(), m_Numbers.end(), [](ContactMethod* a, ContactMethod* b){ - return (a->lastUsed() < b->lastUsed()); - }); - - return (*lastPhoneNumberUsed) ? (*lastPhoneNumberUsed)->bestId() : QString(); -} - PersonPrivate::PersonPrivate(Person* contact) : QObject(nullptr), m_Numbers(),m_DisplayPhoto(false),m_Active(true),m_isPlaceHolder(false), m_LastUsed(0),m_LastUsedInit(false), q_ptr(contact) @@ -366,6 +353,15 @@ const QString& Person::department() const return d_ptr->m_Department; } +/// Get the last ContactMethod used with that person. +ContactMethod* Person::lastUsedContactMethod() const +{ + auto lastUsed = std::max_element(phoneNumbers().begin(), phoneNumbers().end(), + [] (ContactMethod* a, ContactMethod* b) { return (a->lastUsed() < b->lastUsed()); } + ); + return *lastUsed; +} + ///Set the phone number (type and number) void Person::setContactMethods(ContactMethods numbers) { @@ -629,7 +625,10 @@ QVariant Person::roleData(int role) const case static_cast<int>(Ring::Role::IsPresent): return isPresent(); case static_cast<int>(Person::Role::IdOfLastCMUsed): - return d_ptr->getLastIdUsed(); + { + auto cm = lastUsedContactMethod(); + return cm ? cm->bestId() : QString(); + } case static_cast<int>(Ring::Role::UnreadTextMessageCount): { int unread = 0; diff --git a/src/person.h b/src/person.h index 78b72daa77d518d4eac94cbc78666650facd9f36..a96b1570a7990d8e6f7dbcde2e7d6b0883e565be 100644 --- a/src/person.h +++ b/src/person.h @@ -142,6 +142,7 @@ public: const QString& group () const; const QString& department () const; time_t lastUsedTime () const; + ContactMethod* lastUsedContactMethod() const; Q_INVOKABLE QVariant roleData (int role) const; Q_INVOKABLE QMimeData* mimePayload( ) const; diff --git a/src/private/person_p.h b/src/private/person_p.h index eebc63cf5d5137803d5ff1ee678060aeef4345cd..9ed62aaf306323f811cbe3c13d792c7a28dba467 100644 --- a/src/private/person_p.h +++ b/src/private/person_p.h @@ -81,7 +81,6 @@ public: //Helper void registerContactMethod(ContactMethod* m); - QString getLastIdUsed(); public Q_SLOTS: void slotLastUsedTimeChanged(::time_t t);