From ea99759573d342327c14b7cd5e64a38824d41846 Mon Sep 17 00:00:00 2001
From: Vincent Texier <vit@free.fr>
Date: Sun, 11 Jan 2015 17:33:19 +0100
Subject: [PATCH] Fix bug in adding contact that already exists

---
 src/cutecoin/core/account.py    | 7 ++++++-
 src/cutecoin/gui/add_contact.py | 7 ++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py
index b81b5405..e490f5f0 100644
--- a/src/cutecoin/core/account.py
+++ b/src/cutecoin/core/account.py
@@ -82,7 +82,12 @@ class Account(object):
         return (key.pubkey == self.pubkey)
 
     def add_contact(self, person):
-        self.contacts.append(person)
+        same_contact = [contact for contact in self.contacts if person.pubkey == contact.pubkey]
+        if len(same_contact) == 0:
+            print("add contact")
+            self.contacts.append(person)
+            return True
+        return False
 
     def add_community(self, server, port):
         logging.debug("Adding a community")
diff --git a/src/cutecoin/gui/add_contact.py b/src/cutecoin/gui/add_contact.py
index d6fae219..4e9546d3 100644
--- a/src/cutecoin/gui/add_contact.py
+++ b/src/cutecoin/gui/add_contact.py
@@ -31,9 +31,10 @@ class AddContactDialog(QDialog, Ui_AddContactDialog):
     def accept(self):
         name = self.edit_name.text()
         pubkey = self.edit_pubkey.text()
-        self.account.add_contact(Person(name, pubkey))
-        self.main_window.menu_contacts_list.addAction(name)
-        self.main_window.app.save(self.account)
+        result = self.account.add_contact(Person(name, pubkey))
+        if result:
+            self.main_window.menu_contacts_list.addAction(name)
+            self.main_window.app.save(self.account)
         self.close()
 
     def name_edited(self, new_name):
-- 
GitLab