contact selection fixes

This commit is contained in:
ingvar1995 2018-07-29 16:11:34 +03:00
parent 250551e752
commit c66dcb0ca2
2 changed files with 17 additions and 7 deletions

View file

@ -342,9 +342,11 @@ class ContactsManager(ToxSave):
def add_group(self, group_number): def add_group(self, group_number):
group = self._contact_provider.get_group_by_number(group_number) group = self._contact_provider.get_group_by_number(group_number)
index = len(self._contacts)
self._contacts.append(group) self._contacts.append(group)
group.reset_avatar(self._settings['identicons']) group.reset_avatar(self._settings['identicons'])
self._save_profile() self._save_profile()
self.set_active(index)
self.update_filtration() self.update_filtration()
def delete_group(self, group_number): def delete_group(self, group_number):
@ -402,6 +404,7 @@ class ContactsManager(ToxSave):
self._tox.friend_add(tox_id, message.encode('utf-8')) self._tox.friend_add(tox_id, message.encode('utf-8'))
tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2] tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2]
self._add_friend(tox_id) self._add_friend(tox_id)
self.update_filtration()
self.save_profile() self.save_profile()
return True return True
except Exception as ex: # wrong data except Exception as ex: # wrong data
@ -459,7 +462,7 @@ class ContactsManager(ToxSave):
self._load_friends() self._load_friends()
self._load_groups() self._load_groups()
if len(self._contacts): 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): for contact in filter(lambda c: not c.has_avatar(), self._contacts):
contact.reset_avatar(self._settings['identicons']) contact.reset_avatar(self._settings['identicons'])
self.update_filtration() self.update_filtration()
@ -512,10 +515,12 @@ class ContactsManager(ToxSave):
def _add_friend(self, tox_id): def _add_friend(self, tox_id):
self._history.add_friend_to_db(tox_id) self._history.add_friend_to_db(tox_id)
friend = self._contact_provider.get_friend_by_public_key(tox_id) friend = self._contact_provider.get_friend_by_public_key(tox_id)
index = len(self._contacts)
self._contacts.append(friend) self._contacts.append(friend)
if not friend.has_avatar(): if not friend.has_avatar():
friend.reset_avatar(self._settings['identicons']) friend.reset_avatar(self._settings['identicons'])
self._save_profile() self._save_profile()
self.set_active(index)
def _save_profile(self): def _save_profile(self):
data = self._tox.get_savedata() data = self._tox.get_savedata()
@ -536,12 +541,14 @@ class ContactsManager(ToxSave):
remove(avatar_path) remove(avatar_path)
def _delete_contact(self, num): def _delete_contact(self, num):
if num == self._active_contact: # active friend was deleted if len(self._contacts) == 1:
if len(self._contacts) == 0: self.set_active(-1)
self.set_active(-1) else:
else: self.set_active(0)
self._screen.select_contact_row(0)
self._contact_provider.remove_contact_from_cache(self._contacts[num].tox_id) self._contact_provider.remove_contact_from_cache(self._contacts[num].tox_id)
del self._contacts[num] del self._contacts[num]
self._screen.friends_list.takeItem(num) self._screen.friends_list.takeItem(num)
self._save_profile() self._save_profile()
self.update_filtration()

View file

@ -713,9 +713,12 @@ class MainWindow(QtWidgets.QMainWindow):
if self._should_show_group_peers_list: if self._should_show_group_peers_list:
self._groups_service.generate_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: if self._should_show_group_peers_list:
self._toggle_gc_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() self.resizeEvent()
def _open_gc_invites_list(self): def _open_gc_invites_list(self):