Skip to content
Snippets Groups Projects
Commit 4fd15aa8 authored by Alexandre Lision's avatar Alexandre Lision
Browse files

contactmethod: update lastUsed with text timestamp

ContactMethods were updated based on calls timestamps
This commit updates the last used timestamp when a new text message
is added to the contactmethod.

Tuleap: #202
Change-Id: I2e4ba288ca5004936d52f6848b931367fbf888f4
parent dd2ca1d2
No related branches found
No related tags found
No related merge requests found
...@@ -294,6 +294,15 @@ bool ContactMethod::setType(ContactMethod::Type t) ...@@ -294,6 +294,15 @@ bool ContactMethod::setType(ContactMethod::Type t)
return false; return false;
} }
///Update the last time used only if t is more recent than m_LastUsed
void ContactMethod::setLastUsed(time_t t)
{
if (t > d_ptr->m_LastUsed) {
d_ptr->m_LastUsed = t;
emit lastUsedChanged(t);
}
}
///Set if this number is tracking presence information ///Set if this number is tracking presence information
void ContactMethod::setTracked(bool track) void ContactMethod::setTracked(bool track)
{ {
...@@ -490,7 +499,7 @@ QVariant ContactMethod::roleData(int role) const ...@@ -490,7 +499,7 @@ QVariant ContactMethod::roleData(int role) const
break; break;
case static_cast<int>(Ring::Role::LastUsed): case static_cast<int>(Ring::Role::LastUsed):
case static_cast<int>(Call::Role::Date): case static_cast<int>(Call::Role::Date):
cat = cat = !lastCall ? QVariant() : QDateTime::fromTime_t(lastCall->startTimeStamp()); cat = d_ptr->m_LastUsed <= 0 ? QVariant() : QDateTime::fromTime_t(d_ptr->m_LastUsed);
break; break;
case static_cast<int>(Ring::Role::Length): case static_cast<int>(Ring::Role::Length):
case static_cast<int>(Call::Role::Length): case static_cast<int>(Call::Role::Length):
...@@ -498,16 +507,14 @@ QVariant ContactMethod::roleData(int role) const ...@@ -498,16 +507,14 @@ QVariant ContactMethod::roleData(int role) const
break; break;
case static_cast<int>(Ring::Role::FormattedLastUsed): case static_cast<int>(Ring::Role::FormattedLastUsed):
case static_cast<int>(Call::Role::FormattedDate): case static_cast<int>(Call::Role::FormattedDate):
cat = !lastCall ? QVariant() : HistoryTimeCategoryModel::timeToHistoryCategory(lastCall->startTimeStamp()); case static_cast<int>(Call::Role::FuzzyDate):
cat = HistoryTimeCategoryModel::timeToHistoryCategory(d_ptr->m_LastUsed);
break; break;
case static_cast<int>(Ring::Role::IndexedLastUsed): case static_cast<int>(Ring::Role::IndexedLastUsed):
return QVariant(static_cast<int>(HistoryTimeCategoryModel::timeToHistoryConst(lastCall->startTimeStamp()))); return QVariant(static_cast<int>(HistoryTimeCategoryModel::timeToHistoryConst(d_ptr->m_LastUsed)));
case static_cast<int>(Call::Role::HasAVRecording): case static_cast<int>(Call::Role::HasAVRecording):
cat = cat = !lastCall ? QVariant() : lastCall->isAVRecording(); cat = cat = !lastCall ? QVariant() : lastCall->isAVRecording();
break; break;
case static_cast<int>(Call::Role::FuzzyDate):
cat = cat = !lastCall ? QVariant() : HistoryTimeCategoryModel::timeToHistoryCategory(lastCall->startTimeStamp());
break;
case static_cast<int>(Call::Role::ContactMethod): case static_cast<int>(Call::Role::ContactMethod):
case static_cast<int>(Ring::Role::Object): case static_cast<int>(Ring::Role::Object):
case static_cast<int>(Role::Object): case static_cast<int>(Role::Object):
...@@ -576,17 +583,12 @@ void ContactMethod::addCall(Call* call) ...@@ -576,17 +583,12 @@ void ContactMethod::addCall(Call* call)
d_ptr->callAdded(call); d_ptr->callAdded(call);
if (call->startTimeStamp() > d_ptr->m_LastUsed) { setLastUsed(call->startTimeStamp());
d_ptr->m_LastUsed = call->startTimeStamp();
if (d_ptr->m_LastUsed)
emit lastUsedChanged(d_ptr->m_LastUsed);
//Notify the account directly. This avoid having to track all contact //Notify the account directly. This avoid having to track all contact
//methods from there //methods from there
if (d_ptr->m_pAccount && d_ptr->m_pAccount->d_ptr->m_LastUsed < d_ptr->m_LastUsed) if (d_ptr->m_pAccount && d_ptr->m_pAccount->d_ptr->m_LastUsed < d_ptr->m_LastUsed)
d_ptr->m_pAccount->d_ptr->m_LastUsed = d_ptr->m_LastUsed; d_ptr->m_pAccount->d_ptr->m_LastUsed = d_ptr->m_LastUsed;
}
d_ptr->changed(); d_ptr->changed();
......
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
//Properties //Properties
Q_PROPERTY(Account* account READ account WRITE setAccount ) Q_PROPERTY(Account* account READ account WRITE setAccount )
Q_PROPERTY(Person* person READ contact WRITE setPerson ) Q_PROPERTY(Person* person READ contact WRITE setPerson )
Q_PROPERTY(int lastUsed READ lastUsed ) Q_PROPERTY(int lastUsed READ lastUsed WRITE setLastUsed )
Q_PROPERTY(QString uri READ uri ) Q_PROPERTY(QString uri READ uri )
Q_PROPERTY(int callCount READ callCount ) Q_PROPERTY(int callCount READ callCount )
Q_PROPERTY(QList<Call*> calls READ calls ) Q_PROPERTY(QList<Call*> calls READ calls )
...@@ -143,6 +143,7 @@ public: ...@@ -143,6 +143,7 @@ public:
void setBookmarked(bool bookmarked); void setBookmarked(bool bookmarked);
void setUid (const QString& uri ); void setUid (const QString& uri );
bool setType (ContactMethod::Type t ); bool setType (ContactMethod::Type t );
void setLastUsed (time_t t );
//Mutator //Mutator
Q_INVOKABLE void addCall(Call* call); Q_INVOKABLE void addCall(Call* call);
......
...@@ -282,9 +282,8 @@ Media::TextRecording* Media::TextRecording::fromJson(const QList<QJsonObject>& i ...@@ -282,9 +282,8 @@ Media::TextRecording* Media::TextRecording::fromJson(const QList<QJsonObject>& i
return t; return t;
} }
void Media::TextRecordingPrivate::insertNewMessage(const QMap<QString,QString>& message, const ContactMethod* cm, Media::Media::Direction direction) void Media::TextRecordingPrivate::insertNewMessage(const QMap<QString,QString>& message, ContactMethod* cm, Media::Media::Direction direction)
{ {
//Only create it if none was found on the disk //Only create it if none was found on the disk
if (!m_pCurrentGroup) { if (!m_pCurrentGroup) {
m_pCurrentGroup = new Serializable::Group(); m_pCurrentGroup = new Serializable::Group();
...@@ -356,6 +355,7 @@ void Media::TextRecordingPrivate::insertNewMessage(const QMap<QString,QString>& ...@@ -356,6 +355,7 @@ void Media::TextRecordingPrivate::insertNewMessage(const QMap<QString,QString>&
//Save the conversation //Save the conversation
q_ptr->save(); q_ptr->save();
cm->setLastUsed(currentTime);
emit q_ptr->messageInserted(message, const_cast<ContactMethod*>(cm), direction); emit q_ptr->messageInserted(message, const_cast<ContactMethod*>(cm), direction);
} }
......
...@@ -161,7 +161,7 @@ public: ...@@ -161,7 +161,7 @@ public:
QAbstractItemModel* m_pTextMessagesModels {nullptr}; QAbstractItemModel* m_pTextMessagesModels {nullptr};
//Helper //Helper
void insertNewMessage(const QMap<QString,QString>& message, const ContactMethod* cm, Media::Media::Direction direction); void insertNewMessage(const QMap<QString,QString>& message, ContactMethod* cm, Media::Media::Direction direction);
QHash<QByteArray,QByteArray> toJsons() const; QHash<QByteArray,QByteArray> toJsons() const;
private: private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment