From f57ea0000174e48d37f96cbe32671eddd819a8a3 Mon Sep 17 00:00:00 2001
From: Hugo Lefeuvre <hugo.lefeuvre@savoirfairelinux.com>
Date: Mon, 14 May 2018 13:24:50 -0400
Subject: [PATCH] contactmodel: introduce bannedStatusChanged signal

cb08d76 introduced a new banned contacts logic to the contact model,
which allows to manage banned contacts without using the old lrc.
While this patch is fully functional, the problem of how exactly the
client is notified about a banning / unbanning operation is still
unclear: currently the only way the client gets notified is via the
refreshFilter() operation. This is enough for managing banned
contacts in the smart list, but not in the banned contacts view.

In order to addres this problem we introduce a new signal,
bannedStatusChanged, which allows the client to be notified when a
contact is banned or unbanned.

Change-Id: I2ea845e0fe311048479777504b74885cb931aa13
Reviewed-by: Sebastien Blin <sebastien.blin@savoirfairelinux.com>
---
 src/api/contactmodel.h | 6 ++++++
 src/contactmodel.cpp   | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/src/api/contactmodel.h b/src/api/contactmodel.h
index b0abbc32..0bacb15a 100644
--- a/src/api/contactmodel.h
+++ b/src/api/contactmodel.h
@@ -152,6 +152,12 @@ Q_SIGNALS:
      * @param transferInfo DataTransferInfo structure from daemon
      */
     void newAccountTransfer(long long dringId, datatransfer::Info info) const;
+    /**
+     * Connect this signal to know when a contact is banned or unbanned
+     * @param contactUri
+     * @param banned whether contact was banned or unbanned
+     */
+    void bannedStatusChanged(const std::string& contactUri, bool banned) const;
 
 private:
     std::unique_ptr<ContactModelPimpl> pimpl_;
diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp
index 150f4cba..a6dd776c 100644
--- a/src/contactmodel.cpp
+++ b/src/contactmodel.cpp
@@ -565,6 +565,7 @@ ContactModelPimpl::slotContactAdded(const std::string& accountId, const std::str
     if (isBanned) {
         // Update the smartlist
         linked.owner.conversationModel->refreshFilter();
+        emit linked.bannedStatusChanged(contactUri, false);
     } else {
         emit linked.contactAdded(contactUri);
     }
@@ -618,6 +619,7 @@ ContactModelPimpl::slotContactRemoved(const std::string& accountId, const std::s
     if (banned) {
         // Update the smartlist
         linked.owner.conversationModel->refreshFilter();
+        emit linked.bannedStatusChanged(contactUri, true);
     } else {
         emit linked.contactRemoved(contactUri);
     }
-- 
GitLab