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
Branches
Tags
No related merge requests found
......@@ -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;
......
......@@ -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
......
......@@ -81,6 +81,7 @@ public:
//Helper
void registerContactMethod(ContactMethod* m);
QString getLastIdUsed();
public Q_SLOTS:
void slotLastUsedTimeChanged(::time_t t);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment