From ab154eacd84f7ab1c1acfc0a40a47a476ab98d99 Mon Sep 17 00:00:00 2001
From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
Date: Wed, 13 Jan 2016 17:19:58 -0500
Subject: [PATCH] TextRecording: add helper to mark all read

So that we can mark all messages as being read without having to
re-save the recording on disk for each message.

Change-Id: I698dbacd0a3f5b2040bdb3a340d1e8bca4e94508
Tuleap: #203
---
 src/media/textrecording.cpp | 18 ++++++++++++++++++
 src/media/textrecording.h   |  3 +++
 2 files changed, 21 insertions(+)

diff --git a/src/media/textrecording.cpp b/src/media/textrecording.cpp
index c3467b81..dee46bf0 100644
--- a/src/media/textrecording.cpp
+++ b/src/media/textrecording.cpp
@@ -181,6 +181,24 @@ QAbstractItemModel* Media::TextRecording::instantMessagingModel() const
    return d_ptr->m_pImModel;
 }
 
+///Set all messages as read and then save the recording
+void Media::TextRecording::setAllRead()
+{
+    bool changed = false;
+    for(int row = 0; row < d_ptr->m_lNodes.size(); ++row) {
+        if (!d_ptr->m_lNodes[row]->m_pMessage->isRead) {
+            d_ptr->m_lNodes[row]->m_pMessage->isRead = true;
+            if (d_ptr->m_pImModel) {
+                auto idx = d_ptr->m_pImModel->index(row, 0);
+                emit d_ptr->m_pImModel->dataChanged(idx,idx);
+            }
+            changed = true;
+        }
+    }
+    if (changed)
+        save();
+}
+
 /**
  * I (Emmanuel Lepage) is in the process of writing a better one for this that
  * can be upstreamed into Qt (there is interest in merging a generic QVariant
diff --git a/src/media/textrecording.h b/src/media/textrecording.h
index 7de7965e..b038f864 100644
--- a/src/media/textrecording.h
+++ b/src/media/textrecording.h
@@ -73,6 +73,9 @@ public:
    bool                hasMimeType              ( const QString& mimeType ) const;
    QStringList         mimeTypes                (                         ) const;
 
+   //Helper
+   void setAllRead();
+
 Q_SIGNALS:
    void messageInserted(const QMap<QString,QString>& message, ContactMethod* cm, Media::Media::Direction direction);
 
-- 
GitLab