From 7aac248bf9b81546e147bdcfb3d3513f0d2c3b84 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Tue, 10 Jul 2018 00:41:08 +0300 Subject: [PATCH] identicons fixes. sending messages button fixed --- toxygen/contacts/basecontact.py | 5 +++++ toxygen/contacts/contacts_manager.py | 19 ++++++++++++------- toxygen/ui/main_screen.py | 3 ++- toxygen/utils/util.py | 4 ++++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/toxygen/contacts/basecontact.py b/toxygen/contacts/basecontact.py index 0357809..fa709db 100644 --- a/toxygen/contacts/basecontact.py +++ b/toxygen/contacts/basecontact.py @@ -148,6 +148,11 @@ class BaseContact: return util.join_path(directory, '{}.png'.format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2])) + def has_avatar(self): + path = self.get_contact_avatar_path() + + return util.file_exists(path) + def get_avatar_changed_event(self): return self._avatar_changed_event diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index 46e98a2..6812391 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -296,11 +296,7 @@ class ContactsManager(ToxSave): Adds friend to list """ self._tox.friend_add_norequest(tox_id) - self._history.add_friend_to_db(tox_id) - friend = self._contact_provider.get_friend_by_public_key(tox_id) - self._contacts.append(friend) - friend.reset_avatar(self._settings['identicons']) - self._save_profile() + self._add_friend(tox_id) def block_user(self, tox_id): """ @@ -375,8 +371,7 @@ class ContactsManager(ToxSave): else: self._tox.friend_add(tox_id, message.encode('utf-8')) tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2] - friend = self._contact_provider.get_friend_by_public_key(tox_id) - self._contacts.append(friend) + self._add_friend(tox_id) self.save_profile() return True except Exception as ex: # wrong data @@ -430,6 +425,8 @@ class ContactsManager(ToxSave): self._load_groups() if len(self._contacts): self.set_active(0) + for contact in filter(lambda c: not c.has_avatar(), self._contacts): + contact.reset_avatar(self._settings['identicons']) self.update_filtration() def _load_friends(self): @@ -477,6 +474,14 @@ class ContactsManager(ToxSave): self._screen.account_avatar.setPixmap(pixmap.scaled(width, width, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)) + def _add_friend(self, tox_id): + self._history.add_friend_to_db(tox_id) + friend = self._contact_provider.get_friend_by_public_key(tox_id) + self._contacts.append(friend) + if not friend.has_avatar(): + friend.reset_avatar(self._settings['identicons']) + self._save_profile() + def _save_profile(self): data = self._tox.get_savedata() self._profile_manager.save_profile(data) diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index e88437a..5bcd15a 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -17,7 +17,7 @@ class MainWindow(QtWidgets.QMainWindow): self._plugins_loader = None self.setAcceptDrops(True) self._saved = False - self._profile = self._toxes = None + self._profile = self._toxes = self._messenger = None self._file_transfer_handler = self._history_loader = self._groups_service = self._calls_manager = None self._should_show_group_peers_list = False self.initUI() @@ -34,6 +34,7 @@ class MainWindow(QtWidgets.QMainWindow): self._calls_manager = calls_manager self._groups_service = groups_service self._toxes = toxes + self._messenger = messenger self._contacts_manager.active_contact_changed.add_callback(self._new_contact_selected) self.messageEdit.set_messenger(messenger) diff --git a/toxygen/utils/util.py b/toxygen/utils/util.py index 5790a5b..0f718ef 100644 --- a/toxygen/utils/util.py +++ b/toxygen/utils/util.py @@ -102,6 +102,10 @@ def join_path(a, b): return os.path.join(a, b) +def file_exists(file_path): + return os.path.exists(file_path) + + def copy(src, dest): if not os.path.exists(dest): os.makedirs(dest)