Skip to content
Snippets Groups Projects
Commit fedf26a6 authored by Alexandre Lision's avatar Alexandre Lision Committed by Edric Milaret
Browse files

chat: track unread message count

Each TextRecording object tracks the number of unread messages and report it to
the RecordingModel. It allows to display a global notice on how many text
messages are unread in the app.

Change-Id: I5053466ffa9b678cf35c67a62adc3a5849a06e4f
Tuleap: #202
parent 3e5c8a62
No related branches found
No related tags found
No related merge requests found
...@@ -63,9 +63,12 @@ public: ...@@ -63,9 +63,12 @@ public:
RecordingNode* m_pText ; RecordingNode* m_pText ;
RecordingNode* m_pAudioVideo ; RecordingNode* m_pAudioVideo ;
LocalTextRecordingCollection* m_pTextRecordingCollection; LocalTextRecordingCollection* m_pTextRecordingCollection;
int m_UnreadCount ;
//RecordingNode* m_pFiles ; //TODO uncomment when implemented in DRing //RecordingNode* m_pFiles ; //TODO uncomment when implemented in DRing
void forwardInsertion(const QMap<QString,QString>& message, ContactMethod* cm, Media::Media::Direction direction); void forwardInsertion(const QMap<QString,QString>& message, ContactMethod* cm, Media::Media::Direction direction);
void updateUnreadCount(const int count);
private: private:
Media::RecordingModel* q_ptr; Media::RecordingModel* q_ptr;
...@@ -90,6 +93,15 @@ void RecordingModelPrivate::forwardInsertion(const QMap<QString,QString>& messag ...@@ -90,6 +93,15 @@ void RecordingModelPrivate::forwardInsertion(const QMap<QString,QString>& messag
emit q_ptr->newTextMessage(static_cast<Media::TextRecording*>(sender()), cm); emit q_ptr->newTextMessage(static_cast<Media::TextRecording*>(sender()), cm);
} }
void RecordingModelPrivate::updateUnreadCount(const int count)
{
m_UnreadCount += count;
if (m_UnreadCount <= 0) {
m_UnreadCount = 0;
}
emit q_ptr->unreadMessagesCountChanged(m_UnreadCount);
}
Media::RecordingModel::~RecordingModel() Media::RecordingModel::~RecordingModel()
{ {
delete d_ptr; delete d_ptr;
...@@ -264,6 +276,7 @@ bool Media::RecordingModel::addItemCallback(const Recording* item) ...@@ -264,6 +276,7 @@ bool Media::RecordingModel::addItemCallback(const Recording* item)
if (item->type() == Recording::Type::TEXT) { if (item->type() == Recording::Type::TEXT) {
const TextRecording* r = static_cast<const TextRecording*>(item); const TextRecording* r = static_cast<const TextRecording*>(item);
connect(r, &TextRecording::messageInserted, d_ptr, &RecordingModelPrivate::forwardInsertion); connect(r, &TextRecording::messageInserted, d_ptr, &RecordingModelPrivate::forwardInsertion);
connect(r, &TextRecording::unreadCountChange, d_ptr, &RecordingModelPrivate::updateUnreadCount);
} }
return true; return true;
...@@ -321,6 +334,11 @@ void Media::RecordingModel::setAlwaysRecording(bool record) ...@@ -321,6 +334,11 @@ void Media::RecordingModel::setAlwaysRecording(bool record)
configurationManager.setIsAlwaysRecording ( record ); configurationManager.setIsAlwaysRecording ( record );
} }
int Media::RecordingModel::unreadCount() const
{
return d_ptr->m_UnreadCount;
}
///Create or load the recording associated with the ContactMethod cm ///Create or load the recording associated with the ContactMethod cm
Media::TextRecording* Media::RecordingModel::createTextRecording(const ContactMethod* cm) Media::TextRecording* Media::RecordingModel::createTextRecording(const ContactMethod* cm)
{ {
......
...@@ -73,6 +73,7 @@ public: ...@@ -73,6 +73,7 @@ public:
//Getter //Getter
bool isAlwaysRecording() const; bool isAlwaysRecording() const;
QUrl recordPath () const; QUrl recordPath () const;
int unreadCount () const;
//Setter //Setter
void setAlwaysRecording( bool record ); void setAlwaysRecording( bool record );
...@@ -86,6 +87,7 @@ public: ...@@ -86,6 +87,7 @@ public:
Q_SIGNALS: Q_SIGNALS:
void newTextMessage(TextRecording* t, ContactMethod* cm); void newTextMessage(TextRecording* t, ContactMethod* cm);
void unreadMessagesCountChanged(int unreadCount);
private: private:
RecordingModelPrivate* d_ptr; RecordingModelPrivate* d_ptr;
...@@ -98,4 +100,3 @@ private: ...@@ -98,4 +100,3 @@ private:
}; };
} }
...@@ -147,7 +147,7 @@ Serializable::Peers* SerializableEntityManager::fromJson(const QJsonObject& json ...@@ -147,7 +147,7 @@ Serializable::Peers* SerializableEntityManager::fromJson(const QJsonObject& json
return p; return p;
} }
Media::TextRecordingPrivate::TextRecordingPrivate(TextRecording* r) : q_ptr(r),m_pImModel(nullptr),m_pCurrentGroup(nullptr) Media::TextRecordingPrivate::TextRecordingPrivate(TextRecording* r) : q_ptr(r),m_pImModel(nullptr),m_pCurrentGroup(nullptr),m_UnreadCount(0)
{ {
} }
...@@ -198,6 +198,9 @@ void Media::TextRecording::setAllRead() ...@@ -198,6 +198,9 @@ void Media::TextRecording::setAllRead()
if (changed) { if (changed) {
// TODO: we assume that the CM is the same for now, and that at least some of the messages // TODO: we assume that the CM is the same for now, and that at least some of the messages
// are text // are text
int oldVal = d_ptr->m_UnreadCount;
d_ptr->m_UnreadCount = 0;
emit unreadCountChange(-oldVal);
emit d_ptr->m_lNodes[0]->m_pContactMethod->unreadTextMessageCountChanged(); emit d_ptr->m_lNodes[0]->m_pContactMethod->unreadTextMessageCountChanged();
emit d_ptr->m_lNodes[0]->m_pContactMethod->changed(); emit d_ptr->m_lNodes[0]->m_pContactMethod->changed();
save(); save();
...@@ -415,6 +418,8 @@ void Media::TextRecordingPrivate::insertNewMessage(const QMap<QString,QString>& ...@@ -415,6 +418,8 @@ void Media::TextRecordingPrivate::insertNewMessage(const QMap<QString,QString>&
cm->setLastUsed(currentTime); cm->setLastUsed(currentTime);
emit q_ptr->messageInserted(message, const_cast<ContactMethod*>(cm), direction); emit q_ptr->messageInserted(message, const_cast<ContactMethod*>(cm), direction);
if (!m->isRead) { if (!m->isRead) {
m_UnreadCount += 1;
emit q_ptr->unreadCountChange(1);
emit cm->unreadTextMessageCountChanged(); emit cm->unreadTextMessageCountChanged();
emit cm->changed(); emit cm->changed();
} }
...@@ -705,6 +710,9 @@ bool InstantMessagingModel::setData(const QModelIndex& idx, const QVariant &valu ...@@ -705,6 +710,9 @@ bool InstantMessagingModel::setData(const QModelIndex& idx, const QVariant &valu
if (n->m_pMessage->isRead != value.toBool()) { if (n->m_pMessage->isRead != value.toBool()) {
n->m_pMessage->isRead = value.toBool(); n->m_pMessage->isRead = value.toBool();
if (n->m_pMessage->m_HasText) { if (n->m_pMessage->m_HasText) {
int val = value.toBool() ? -1 : +1;
m_pRecording->d_ptr->m_UnreadCount += val;
emit m_pRecording->unreadCountChange(val);
emit n->m_pContactMethod->unreadTextMessageCountChanged(); emit n->m_pContactMethod->unreadTextMessageCountChanged();
emit n->m_pContactMethod->changed(); emit n->m_pContactMethod->changed();
} }
......
...@@ -79,6 +79,7 @@ public: ...@@ -79,6 +79,7 @@ public:
Q_SIGNALS: Q_SIGNALS:
void messageInserted(const QMap<QString,QString>& message, ContactMethod* cm, Media::Media::Direction direction); void messageInserted(const QMap<QString,QString>& message, ContactMethod* cm, Media::Media::Direction direction);
void unreadCountChange(int count);
private: private:
TextRecordingPrivate* d_ptr; TextRecordingPrivate* d_ptr;
......
...@@ -157,6 +157,7 @@ public: ...@@ -157,6 +157,7 @@ public:
Serializable::Group* m_pCurrentGroup ; Serializable::Group* m_pCurrentGroup ;
QList<Serializable::Peers*> m_lAssociatedPeers ; QList<Serializable::Peers*> m_lAssociatedPeers ;
QHash<QString,bool> m_hMimeTypes ; QHash<QString,bool> m_hMimeTypes ;
int m_UnreadCount ;
QStringList m_lMimeTypes ; QStringList m_lMimeTypes ;
QAbstractItemModel* m_pTextMessagesModel {nullptr}; QAbstractItemModel* m_pTextMessagesModel {nullptr};
QAbstractItemModel* m_pUnreadTextMessagesModel {nullptr}; QAbstractItemModel* m_pUnreadTextMessagesModel {nullptr};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment