From 1be57bd503cd43501ac08eb26c5bdc096e393d76 Mon Sep 17 00:00:00 2001
From: Ming Rui Zhang <mingrui.zhang@savoirfairelinux.com>
Date: Tue, 1 Oct 2019 14:02:43 -0400
Subject: [PATCH] newcallmodel: add voicemail notification related signals

Change-Id: I86c0be35cc56b03b39279d239fe77bb83fe5240c
---
 src/api/newcallmodel.h           |  9 +++++++++
 src/callbackshandler.cpp         | 12 ++++++++++++
 src/callbackshandler.h           | 21 +++++++++++++++++++++
 src/newcallmodel.cpp             | 15 +++++++++++++++
 src/qtwrapper/callmanager_wrap.h |  8 ++++----
 test/mocks/callmanager_mock.h    |  2 +-
 6 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/src/api/newcallmodel.h b/src/api/newcallmodel.h
index dbf8b549..af80deec 100644
--- a/src/api/newcallmodel.h
+++ b/src/api/newcallmodel.h
@@ -251,6 +251,15 @@ Q_SIGNALS:
      */
     void callAddedToConference(const std::string& callId, const std::string& confId) const;
 
+    /**
+     * Emitted when a voice mail notice arrives
+     * @param accountId
+     * @param newCount
+     * @param oldCount
+     * @param urgentCount
+     */
+    void voiceMailNotify(const std::string& accountId, int newCount, int oldCount, int urgentCount) const;
+
 private:
     std::unique_ptr<NewCallModelPimpl> pimpl_;
 };
diff --git a/src/callbackshandler.cpp b/src/callbackshandler.cpp
index fbda0d06..e043aa90 100644
--- a/src/callbackshandler.cpp
+++ b/src/callbackshandler.cpp
@@ -145,6 +145,12 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent)
             &CallbacksHandler::slotIncomingMessage,
             Qt::QueuedConnection);
 
+    connect(&CallManager::instance(),
+            &CallManagerInterface::voiceMailNotify,
+            this,
+            &CallbacksHandler::slotVoiceMailNotify,
+            Qt::QueuedConnection);
+
     connect(&ConfigurationManager::instance(),
             &ConfigurationManagerInterface::dataTransferEvent,
             this,
@@ -264,6 +270,12 @@ CallbacksHandler::slotNearbyPeerSubscription(const QString& accountId,
     emit newPeerSubscription(accountId.toStdString(), contactUri.toStdString(), state, displayname.toStdString());
 }
 
+void
+CallbacksHandler::slotVoiceMailNotify(const QString& accountId, int newCount, int oldCount, int urgentCount)
+{
+    emit voiceMailNotify(accountId.toStdString(), newCount, oldCount, urgentCount);
+}
+
 void
 CallbacksHandler::slotContactAdded(const QString& accountId,
                                    const QString& contactUri,
diff --git a/src/callbackshandler.h b/src/callbackshandler.h
index 4f38a306..ab1e69bd 100644
--- a/src/callbackshandler.h
+++ b/src/callbackshandler.h
@@ -268,6 +268,15 @@ Q_SIGNALS:
      */
     void audioMeter(const std::string& id, float level);
 
+    /**
+     * Emitted when an audio level is received
+     * @param accountId
+     * @param newCount
+     * @param oldCount
+     * @param urgentCount
+     */
+    void voiceMailNotify(const std::string& accountId, int newCount, int oldCount, int urgentCount);
+
 private Q_SLOTS:
     /**
      * Emit newAccountMessage
@@ -488,6 +497,18 @@ private Q_SLOTS:
                                     int state,
                                     const QString& displayname);
 
+    /**
+     * Emit voiceMailNotify
+     * @param accountId
+     * @param new VM
+     * @param old VM
+     * @param new Urgent VM
+     */
+    void slotVoiceMailNotify(const QString& accountId,
+                             int newCount,
+                             int oldCount,
+                             int urgentCount);
+
 private:
     const api::Lrc& parent;
 };
diff --git a/src/newcallmodel.cpp b/src/newcallmodel.cpp
index 4d8e74d1..b75425ae 100644
--- a/src/newcallmodel.cpp
+++ b/src/newcallmodel.cpp
@@ -166,6 +166,14 @@ public Q_SLOTS:
      * @param callId
      */
     void slotConferenceCreated(const std::string& callId);
+    /**
+     * Listen from CallbacksHandler when a voice mail notice is incoming
+     * @param accountId
+     * @param newCount
+     * @param oldCount
+     * @param urgentCount
+     */
+    void slotVoiceMailNotify(const std::string& accountId, int newCount, int oldCount, int urgentCount);
 };
 
 NewCallModel::NewCallModel(const account::Info& owner, const CallbacksHandler& callbacksHandler)
@@ -423,6 +431,7 @@ NewCallModelPimpl::NewCallModelPimpl(const NewCallModel& linked, const Callbacks
     connect(&callbacksHandler, &CallbacksHandler::callStateChanged, this, &NewCallModelPimpl::slotCallStateChanged);
     connect(&callbacksHandler, &CallbacksHandler::incomingVCardChunk, this, &NewCallModelPimpl::slotincomingVCardChunk);
     connect(&callbacksHandler, &CallbacksHandler::conferenceCreated, this , &NewCallModelPimpl::slotConferenceCreated);
+    connect(&callbacksHandler, &CallbacksHandler::voiceMailNotify, this, &NewCallModelPimpl::slotVoiceMailNotify);
 
 #ifndef ENABLE_LIBWRAP
     // Only necessary with dbus since the daemon runs separately
@@ -630,6 +639,12 @@ NewCallModelPimpl::slotincomingVCardChunk(const std::string& callId,
     }
 }
 
+void
+NewCallModelPimpl::slotVoiceMailNotify(const std::string & accountId, int newCount, int oldCount, int urgentCount)
+{
+    emit linked.voiceMailNotify(accountId, newCount, oldCount, urgentCount);
+}
+
 bool
 NewCallModel::hasCall(const std::string& callId) const
 {
diff --git a/src/qtwrapper/callmanager_wrap.h b/src/qtwrapper/callmanager_wrap.h
index 89abadaf..65ea7259 100644
--- a/src/qtwrapper/callmanager_wrap.h
+++ b/src/qtwrapper/callmanager_wrap.h
@@ -69,9 +69,9 @@ public:
                     Q_EMIT recordPlaybackStopped(QString(filepath.c_str()));
                 }),
             exportable_callback<CallSignal::VoiceMailNotify>(
-                [this] (const std::string &accountID, int count) {
-                    LOG_DRING_SIGNAL2("voiceMailNotify",QString(accountID.c_str()), count);
-                    Q_EMIT voiceMailNotify(QString(accountID.c_str()), count);
+                [this] (const std::string &accountId, int newCount, int oldCount, int urgentCount) {
+                    LOG_DRING_SIGNAL4("voiceMailNotify",QString(accountId.c_str()), newCount, oldCount, urgentCount);
+                    Q_EMIT voiceMailNotify(QString(accountId.c_str()), newCount, oldCount, urgentCount);
                 }),
             exportable_callback<CallSignal::IncomingMessage>(
                 [this] (const std::string &callID, const std::string &from, const std::map<std::string,std::string> &message) {
@@ -373,7 +373,7 @@ Q_SIGNALS: // SIGNALS
     void transferFailed();
     void transferSucceeded();
     void recordPlaybackStopped(const QString &filepath);
-    void voiceMailNotify(const QString &accountID, int count);
+    void voiceMailNotify(const QString &accountId, int newCount, int oldCount, int urgentCount);
     void incomingMessage(const QString &callID, const QString &from, const MapStringString &message);
     void incomingCall(const QString &accountID, const QString &callID, const QString &from);
     void recordPlaybackFilepath(const QString &callID, const QString &filepath);
diff --git a/test/mocks/callmanager_mock.h b/test/mocks/callmanager_mock.h
index b28e35cd..071d9808 100644
--- a/test/mocks/callmanager_mock.h
+++ b/test/mocks/callmanager_mock.h
@@ -302,7 +302,7 @@ Q_SIGNALS: // SIGNALS
     void transferFailed();
     void transferSucceeded();
     void recordPlaybackStopped(const QString &filepath);
-    void voiceMailNotify(const QString &accountID, int count);
+    void voiceMailNotify(const QString &accountId, int newCount, int oldCount, int urgentCount);
     void incomingMessage(const QString &callID, const QString &from, const MapStringString &message);
     void incomingCall(const QString &accountID, const QString &callID, const QString &from);
     void recordPlaybackFilepath(const QString &callID, const QString &filepath);
-- 
GitLab