Skip to content
Snippets Groups Projects
Commit 1c43c466 authored by Nicolas Jager's avatar Nicolas Jager Committed by Olivier SOLDANO
Browse files

Person : add getLastIdUsed()


- return the best Id for the last ContactMethod used with Person.

Change-Id: I015f276074b6d39ddee7d727c3dd09cb7f6e6696
Reviewed-by: default avatarOlivier Soldano <olivier.soldano@savoirfairelinux.com>
parent a879b839
No related branches found
No related tags found
No related merge requests found
...@@ -193,6 +193,19 @@ void PersonPrivate::registerContactMethod(ContactMethod* m) ...@@ -193,6 +193,19 @@ void PersonPrivate::registerContactMethod(ContactMethod* m)
slotLastUsedTimeChanged(m->lastUsed()); 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), PersonPrivate::PersonPrivate(Person* contact) : QObject(nullptr),
m_Numbers(),m_DisplayPhoto(false),m_Active(true),m_isPlaceHolder(false), m_Numbers(),m_DisplayPhoto(false),m_Active(true),m_isPlaceHolder(false),
m_LastUsed(0),m_LastUsedInit(false), q_ptr(contact) m_LastUsed(0),m_LastUsedInit(false), q_ptr(contact)
...@@ -615,6 +628,8 @@ QVariant Person::roleData(int role) const ...@@ -615,6 +628,8 @@ QVariant Person::roleData(int role) const
return filterString(); return filterString();
case static_cast<int>(Ring::Role::IsPresent): case static_cast<int>(Ring::Role::IsPresent):
return isPresent(); return isPresent();
case static_cast<int>(Person::Role::IdOfLastCMUsed):
return d_ptr->getLastIdUsed();
case static_cast<int>(Ring::Role::UnreadTextMessageCount): case static_cast<int>(Ring::Role::UnreadTextMessageCount):
{ {
int unread = 0; int unread = 0;
......
...@@ -55,6 +55,7 @@ public: ...@@ -55,6 +55,7 @@ public:
FormattedLastUsed , FormattedLastUsed ,
IndexedLastUsed , IndexedLastUsed ,
DatedLastUsed , DatedLastUsed ,
IdOfLastCMUsed ,
Object , Object ,
Filter , //All roles, all at once Filter , //All roles, all at once
DropState = static_cast<int>(Ring::Role::DropState), //State for drag and drop DropState = static_cast<int>(Ring::Role::DropState), //State for drag and drop
......
...@@ -81,6 +81,7 @@ public: ...@@ -81,6 +81,7 @@ public:
//Helper //Helper
void registerContactMethod(ContactMethod* m); void registerContactMethod(ContactMethod* m);
QString getLastIdUsed();
public Q_SLOTS: public Q_SLOTS:
void slotLastUsedTimeChanged(::time_t t); void slotLastUsedTimeChanged(::time_t t);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment