From 1c43c466a076815bf621f22ef9e58cdcd51f6d94 Mon Sep 17 00:00:00 2001 From: Nicolas Jager <nicolas.jager@savoirfairelinux.com> Date: Thu, 27 Apr 2017 11:23:03 -0400 Subject: [PATCH] Person : add getLastIdUsed() - return the best Id for the last ContactMethod used with Person. Change-Id: I015f276074b6d39ddee7d727c3dd09cb7f6e6696 Reviewed-by: Olivier Soldano <olivier.soldano@savoirfairelinux.com> --- src/person.cpp | 15 +++++++++++++++ src/person.h | 1 + src/private/person_p.h | 1 + 3 files changed, 17 insertions(+) diff --git a/src/person.cpp b/src/person.cpp index 70aacec5..537502b8 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 f94d534b..78b72daa 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 9ed62aaf..eebc63cf 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); -- GitLab