From b9cdce5179dc217b05eb6561031223819cf852b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Wed, 1 Aug 2018 10:53:15 -0400
Subject: [PATCH] contactmodel: remove useless addContact call

This line is not justified anymore as the daemon seems to emit
everytime the contactAdded signal.
Indeed, this line is fixed by
ring-daemon/1353a641fc064b39a3414ab0cd074dd0ebfcb54c

Change-Id: I94e3b0bdf76658749b70affb847130f843a5dc09
Reviewed-by: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
---
 src/authority/daemon.cpp |  8 ++++----
 src/authority/daemon.h   |  6 ++++--
 src/contactmodel.cpp     | 13 +++++++++----
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/authority/daemon.cpp b/src/authority/daemon.cpp
index 1d93ad2b..8a3e5234 100644
--- a/src/authority/daemon.cpp
+++ b/src/authority/daemon.cpp
@@ -49,17 +49,17 @@ removeContact(const api::account::Info& owner, const std::string& contactUri, bo
     QString(contactUri.c_str()), banned);
 }
 
-void
+bool
 addContactFromPending(const api::account::Info& owner, const std::string& contactUri)
 {
-    ConfigurationManager::instance().acceptTrustRequest(QString(owner.id.c_str()),
+    return ConfigurationManager::instance().acceptTrustRequest(QString(owner.id.c_str()),
     QString(contactUri.c_str()));
 }
 
-void
+bool
 discardFromPending(const api::account::Info& owner, const std::string& contactUri)
 {
-    ConfigurationManager::instance().discardTrustRequest(
+    return ConfigurationManager::instance().discardTrustRequest(
         QString(owner.id.c_str()),
         QString(contactUri.c_str())
     );
diff --git a/src/authority/daemon.h b/src/authority/daemon.h
index 1ba8abec..49be4448 100644
--- a/src/authority/daemon.h
+++ b/src/authority/daemon.h
@@ -54,14 +54,16 @@ void removeContact(const api::account::Info& owner, const std::string& contactUr
  * Ask the daemon to add a contact from the pending list.
  * @param owner
  * @param contactUri
+ * @return if operation succeed
  */
-void addContactFromPending(const api::account::Info& owner, const std::string& contactUri);
+bool addContactFromPending(const api::account::Info& owner, const std::string& contactUri);
 /**
  * Ask the daemon to discard a pending.
  * @param owner
  * @param contactUri
+ * @return if operation succeed
  */
-void discardFromPending(const api::account::Info& owner, const std::string& contactUri);
+bool discardFromPending(const api::account::Info& owner, const std::string& contactUri);
 
 } // namespace daemon
 
diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp
index 81a68420..30e6d3dc 100644
--- a/src/contactmodel.cpp
+++ b/src/contactmodel.cpp
@@ -234,9 +234,11 @@ ContactModel::addContact(contact::Info contactInfo)
 #endif
         break;
     case profile::Type::PENDING:
-        daemon::addContactFromPending(owner, profile.uri);
-        emit pendingContactAccepted(profile.uri);
-        daemon::addContact(owner, profile.uri); // BUGS?: daemon::addContactFromPending not always add the contact
+        if (daemon::addContactFromPending(owner, profile.uri)) {
+            emit pendingContactAccepted(profile.uri);
+        } else {
+            return;
+        }
         break;
     case profile::Type::RING:
     case profile::Type::SIP:
@@ -278,7 +280,10 @@ ContactModel::removeContact(const std::string& contactUri, bool banned)
         if (!banned && contact != pimpl_->contacts.end()
             && contact->second.profileInfo.type == profile::Type::PENDING) {
             // Discard the pending request and remove profile from db if necessary
-            daemon::discardFromPending(owner, contactUri);
+            if(!daemon::discardFromPending(owner, contactUri)) {
+                qDebug() << "Discard request for account " << owner.id.c_str() << " failed (" << contactUri.c_str() << ")";
+                return;
+            }
             pimpl_->contacts.erase(contactUri);
             database::removeContact(pimpl_->db, owner.profileInfo.uri, contactUri);
             emitContactRemoved = true;
-- 
GitLab