From c66dcb0ca2c348bd9e20bbdd056bdcef5795a9cd Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 29 Jul 2018 16:11:34 +0300 Subject: [PATCH] contact selection fixes --- toxygen/contacts/contacts_manager.py | 19 +++++++++++++------ toxygen/ui/main_screen.py | 5 ++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index 0800655..9b4ad93 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -342,9 +342,11 @@ class ContactsManager(ToxSave): def add_group(self, group_number): group = self._contact_provider.get_group_by_number(group_number) + index = len(self._contacts) self._contacts.append(group) group.reset_avatar(self._settings['identicons']) self._save_profile() + self.set_active(index) self.update_filtration() def delete_group(self, group_number): @@ -402,6 +404,7 @@ class ContactsManager(ToxSave): self._tox.friend_add(tox_id, message.encode('utf-8')) tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2] self._add_friend(tox_id) + self.update_filtration() self.save_profile() return True except Exception as ex: # wrong data @@ -459,7 +462,7 @@ class ContactsManager(ToxSave): self._load_friends() self._load_groups() if len(self._contacts): - self._screen.select_contact_row(0) + 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() @@ -512,10 +515,12 @@ class ContactsManager(ToxSave): 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) + index = len(self._contacts) self._contacts.append(friend) if not friend.has_avatar(): friend.reset_avatar(self._settings['identicons']) self._save_profile() + self.set_active(index) def _save_profile(self): data = self._tox.get_savedata() @@ -536,12 +541,14 @@ class ContactsManager(ToxSave): remove(avatar_path) def _delete_contact(self, num): - if num == self._active_contact: # active friend was deleted - if len(self._contacts) == 0: - self.set_active(-1) - else: - self._screen.select_contact_row(0) + if len(self._contacts) == 1: + self.set_active(-1) + else: + self.set_active(0) + self._contact_provider.remove_contact_from_cache(self._contacts[num].tox_id) del self._contacts[num] self._screen.friends_list.takeItem(num) self._save_profile() + + self.update_filtration() diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index 54b6804..edf7ac6 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -713,9 +713,12 @@ class MainWindow(QtWidgets.QMainWindow): if self._should_show_group_peers_list: self._groups_service.generate_peers_list() - def _new_contact_selected(self, contact): + def _new_contact_selected(self, _): if self._should_show_group_peers_list: self._toggle_gc_peers_list() + index = self.friends_list.currentRow() + if self._contacts_manager.active_contact != index: + self.friends_list.setCurrentRow(self._contacts_manager.active_contact) self.resizeEvent() def _open_gc_invites_list(self):