From d4bb2483c6074dfb124a2249d00d41f99c8c1526 Mon Sep 17 00:00:00 2001
From: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
Date: Thu, 31 May 2018 16:15:53 -0400
Subject: [PATCH] smartlist: update info when contact not found
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Update temporary contact when receive lookup return.
Note: like the "Not found" label, don't add the query to the
"Searching…" label

Change-Id: I4fd7dce67ee10132f4b63564d9fbd5d4acb95c30
Reviewed-by: Sebastien Blin <sebastien.blin@savoirfairelinux.com>
---
 src/callbackshandler.cpp |  2 ++
 src/callbackshandler.h   | 10 ++++++++++
 src/contactmodel.cpp     | 31 ++++++++++++++++++++++++++++++-
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/src/callbackshandler.cpp b/src/callbackshandler.cpp
index ceca7114..1814fca4 100644
--- a/src/callbackshandler.cpp
+++ b/src/callbackshandler.cpp
@@ -202,6 +202,8 @@ CallbacksHandler::slotRegisteredNameFound(const Account* account, NameDirectory:
     if (!account) return;
     if (status == NameDirectory::LookupStatus::SUCCESS) {
         emit registeredNameFound(account->id().toStdString(), address.toStdString(), name.toStdString());
+    } else if((!address.trimmed().isEmpty() || !name.trimmed().isEmpty())) {
+        emit registeredNameNotFound(account->id().toStdString(), address.toStdString(), name.toStdString());
     }
 }
 
diff --git a/src/callbackshandler.h b/src/callbackshandler.h
index cd022132..06cf3b67 100644
--- a/src/callbackshandler.h
+++ b/src/callbackshandler.h
@@ -127,6 +127,16 @@ Q_SIGNALS:
     void registeredNameFound(const std::string& accountId,
                              const std::string& uri,
                              const std::string& registeredName);
+
+    /**
+     * Connect this signal to know when a name is not found
+     * @param accountId the account who receives this signal
+     * @param uri the search uri
+     * @param name the search name
+     */
+    void registeredNameNotFound(const std::string& accountId,
+                                const std::string& uri,
+                                const std::string& name);
     /**
      * Connect this signal to know where a VCard is incoming
      * @param callId the call linked to this VCard
diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp
index c4401750..9503c54c 100644
--- a/src/contactmodel.cpp
+++ b/src/contactmodel.cpp
@@ -119,6 +119,13 @@ public Q_SLOTS:
      * @param registeredName of the contact found
      */
     void slotRegisteredNameFound(const std::string& accountId, const std::string& uri, const std::string& registeredName);
+    /**
+     * Listen CallbacksHandler when a name is not found
+     * @param accountId account linked
+     * @param uri the uri to search
+     * @param name the name to search
+     */
+    void slotRegisteredNameNotFound(const std::string& accountId, const std::string& uri, const std::string& name);
     /**
      * Listen CallbacksHandler when an incoming request arrives
      * @param accountId account linked
@@ -352,7 +359,7 @@ ContactModel::searchContact(const std::string& query)
     } else {
         // Default searching
         profile::Info profileInfo;
-        profileInfo.alias = "Searching… " + query;
+        profileInfo.alias = "Searching…";
         profileInfo.type = profile::Type::TEMPORARY;
         temporaryContact.profileInfo = profileInfo;
         temporaryContact.registeredName = query;
@@ -408,6 +415,8 @@ ContactModelPimpl::ContactModelPimpl(const ContactModel& linked,
             this, &ContactModelPimpl::slotIncomingContactRequest);
     connect(&callbacksHandler, &CallbacksHandler::registeredNameFound,
             this, &ContactModelPimpl::slotRegisteredNameFound);
+    connect(&callbacksHandler, &CallbacksHandler::registeredNameNotFound,
+            this, &ContactModelPimpl::slotRegisteredNameNotFound);
     connect(&*linked.owner.callModel, &NewCallModel::newIncomingCall,
             this, &ContactModelPimpl::slotIncomingCall);
     connect(&callbacksHandler, &lrc::CallbacksHandler::newAccountMessage,
@@ -428,6 +437,8 @@ ContactModelPimpl::~ContactModelPimpl()
                this, &ContactModelPimpl::slotIncomingContactRequest);
     disconnect(&callbacksHandler, &CallbacksHandler::registeredNameFound,
                this, &ContactModelPimpl::slotRegisteredNameFound);
+    disconnect(&callbacksHandler, &CallbacksHandler::registeredNameNotFound,
+            this, &ContactModelPimpl::slotRegisteredNameNotFound);
     disconnect(&*linked.owner.callModel, &NewCallModel::newIncomingCall,
                this, &ContactModelPimpl::slotIncomingCall);
     disconnect(&callbacksHandler, &lrc::CallbacksHandler::newAccountMessage,
@@ -683,6 +694,24 @@ ContactModelPimpl::slotRegisteredNameFound(const std::string& accountId,
 
 }
 
+void
+ContactModelPimpl::slotRegisteredNameNotFound(const std::string& accountId,
+                                              const std::string& uri,
+                                              const std::string& name)
+{
+    if (accountId != linked.owner.id) return;
+
+    auto& temporaryContact = contacts[""];
+    if (temporaryContact.registeredName != uri && temporaryContact.registeredName != name) {
+        return;
+    }
+    {
+        std::lock_guard<std::mutex> lk(contactsMtx_);
+        temporaryContact.profileInfo.alias = "Not found";
+    }
+    emit linked.modelUpdated(uri);
+}
+
 void
 ContactModelPimpl::slotIncomingContactRequest(const std::string& accountId,
                                               const std::string& contactUri,
-- 
GitLab