From 5e4f35ac39891714da43c13c4349da96b17fda1c Mon Sep 17 00:00:00 2001
From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
Date: Tue, 11 Oct 2016 17:09:57 -0400
Subject: [PATCH] invoke ContactMethod::addCall() even if the call fails

If the call immediately failed on creation (empty call id returned
by the daemon) the call was not being added to the CM nor the Person
because addCall() was never being called. This created an
inconsistency since the call IS added to the CallModel. Such calls
should either not be added to the CallModel, or else they should be
added to the CM and Person as well. We choose the latter solution
as this is more informative to the user. Otherwise the user has no
way of knowing if the call failed immediately or was just never even
attempted.

Thus this patch ensures ContactMethod::addCall() is called for all
attempted calls. The PhoneDirectoryModel is ammended to not keep
track of statistics for added calls which are in a failed state.

Change-Id: Ie9d2c22a8a9b7fe84d4d02b3887901ac8974130f
Tuleap: #1093
(cherry picked from commit 596f988d2e29dae3bf9e79d6484c977e6180df2d)
---
 src/call.cpp                | 2 +-
 src/phonedirectorymodel.cpp | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/call.cpp b/src/call.cpp
index 45598098..84006267 100644
--- a/src/call.cpp
+++ b/src/call.cpp
@@ -1791,6 +1791,7 @@ void CallPrivate::call()
 
     //Refresh peerCM
     peerCM = q_ptr->peerContactMethod();
+    peerCM->addCall(q_ptr);
 
     m_DringId = CallManager::instance().placeCall(m_Account->id(), uri.full());
 
@@ -1807,7 +1808,6 @@ void CallPrivate::call()
     CallModel::instance().registerCall(q_ptr);
 
     connect(peerCM, SIGNAL(presentChanged(bool)), this, SLOT(updated()));
-    peerCM->addCall(q_ptr);
 
     emit q_ptr->dialNumberChanged(QString());
 }
diff --git a/src/phonedirectorymodel.cpp b/src/phonedirectorymodel.cpp
index a3bcc475..beaa1b2d 100644
--- a/src/phonedirectorymodel.cpp
+++ b/src/phonedirectorymodel.cpp
@@ -293,7 +293,7 @@ QVariant PhoneDirectoryModel::headerData(int section, Qt::Orientation orientatio
    Q_UNUSED(section)
    Q_UNUSED(orientation)
    static const QString headers[] = {tr("URI"), tr("Type"), tr("Person"), tr("Account"), tr("State"), tr("Call count"), tr("Week count"),
-   tr("Trimester count"), tr("Have Called"), tr("Last used"), tr("Name_count"),tr("Total (in seconds)"), tr("Popularity_index"), 
+   tr("Trimester count"), tr("Have Called"), tr("Last used"), tr("Name_count"),tr("Total (in seconds)"), tr("Popularity_index"),
    tr("Bookmarked"), tr("Tracked"), tr("Has certificate"), tr("Present"), tr("Presence message"), tr("Uid") };
    if (role == Qt::DisplayRole) return headers[section];
    return QVariant();
@@ -606,6 +606,10 @@ QVector<ContactMethod*> PhoneDirectoryModel::getNumbersByPopularity() const
 void PhoneDirectoryModelPrivate::slotCallAdded(Call* call)
 {
    Q_UNUSED(call)
+
+   if (call->state() == Call::State::FAILURE)
+      return; //don't update popularity for failed calls
+
    ContactMethod* number = qobject_cast<ContactMethod*>(sender());
    if (number) {
       int currentIndex = number->popularityIndex();
-- 
GitLab