diff --git a/src/person.cpp b/src/person.cpp index 70aacec59d8fcb06c3bc9d51f5ff4dfbe12cb8bc..537502b850f100d80dc9a2f4c9a744a5b1fe07f6 100644 --- a/src/person.cpp +++ b/src/person.cpp @@ -193,6 +193,19 @@ 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)->getBestId() : 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) @@ -615,6 +628,8 @@ QVariant Person::roleData(int role) const return filterString(); case static_cast<int>(Ring::Role::IsPresent): return isPresent(); + case static_cast<int>(Person::Role::IdOfLastCMUsed): + return d_ptr->getLastIdUsed(); case static_cast<int>(Ring::Role::UnreadTextMessageCount): { int unread = 0; diff --git a/src/person.h b/src/person.h index f94d534b99b05949e338e213e40d4404d613850b..78b72daa77d518d4eac94cbc78666650facd9f36 100644 --- a/src/person.h +++ b/src/person.h @@ -55,6 +55,7 @@ public: FormattedLastUsed , IndexedLastUsed , DatedLastUsed , + IdOfLastCMUsed , Object , Filter , //All roles, all at once DropState = static_cast<int>(Ring::Role::DropState), //State for drag and drop diff --git a/src/private/person_p.h b/src/private/person_p.h index 9ed62aaf306323f811cbe3c13d792c7a28dba467..eebc63cf5d5137803d5ff1ee678060aeef4345cd 100644 --- a/src/private/person_p.h +++ b/src/private/person_p.h @@ -81,6 +81,7 @@ public: //Helper void registerContactMethod(ContactMethod* m); + QString getLastIdUsed(); public Q_SLOTS: void slotLastUsedTimeChanged(::time_t t);