diff --git a/toxygen/app.py b/toxygen/app.py index a7fbaff..80c26ea 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -327,6 +327,7 @@ class App: self._calls_manager.set_toxav(self._tox.AV) self._contacts_manager.update_friends_numbers() self._contacts_manager.update_groups_lists() + self._contacts_manager.update_groups_numbers() self._init_callbacks() diff --git a/toxygen/contacts/contact.py b/toxygen/contacts/contact.py index fb124dd..418ac15 100644 --- a/toxygen/contacts/contact.py +++ b/toxygen/contacts/contact.py @@ -43,18 +43,22 @@ class Contact(basecontact.BaseContact): """ :param first_time: friend became active, load first part of messages """ - if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')): - return - if self._message_getter is None: - return - data = list(self._message_getter.get(PAGE_SIZE)) - if data is not None and len(data): - data.reverse() - else: - return - data = list(map(lambda p: self._get_text_message(p), data)) - self._corr = data + self._corr - self._history_loaded = True + try: + if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')): + return + if self._message_getter is None: + return + data = list(self._message_getter.get(PAGE_SIZE)) + if data is not None and len(data): + data.reverse() + else: + return + data = list(map(lambda p: self._get_text_message(p), data)) + self._corr = data + self._corr + except: + pass + finally: + self._history_loaded = True def load_all_corr(self): """ diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index 3499f42..0800655 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -139,13 +139,6 @@ class ContactsManager(ToxSave): active_contact_changed = property(get_active_contact_changed) - def set_active_by_number_and_type(self, number, is_friend): # TODO: by id - for i in range(len(self._contacts)): - c = self._contacts[i] - if c.number == number and (type(c) is Friend == is_friend): - self._active_contact = i - break - def update(self): if self._active_contact + 1: self.set_active(self._active_contact) @@ -309,6 +302,7 @@ class ContactsManager(ToxSave): """ self._tox.friend_add_norequest(tox_id) self._add_friend(tox_id) + self.update_filtration() def block_user(self, tox_id): """ @@ -351,6 +345,7 @@ class ContactsManager(ToxSave): self._contacts.append(group) group.reset_avatar(self._settings['identicons']) self._save_profile() + self.update_filtration() def delete_group(self, group_number): group = self.get_group_by_number(group_number) @@ -464,7 +459,7 @@ class ContactsManager(ToxSave): self._load_friends() self._load_groups() if len(self._contacts): - self.set_active(0) + self._screen.select_contact_row(0) for contact in filter(lambda c: not c.has_avatar(), self._contacts): contact.reset_avatar(self._settings['identicons']) self.update_filtration() @@ -542,7 +537,10 @@ class ContactsManager(ToxSave): def _delete_contact(self, num): if num == self._active_contact: # active friend was deleted - self.set_active(0 if len(self._contacts) > 1 else -1) + if len(self._contacts) == 0: + self.set_active(-1) + else: + self._screen.select_contact_row(0) self._contact_provider.remove_contact_from_cache(self._contacts[num].tox_id) del self._contacts[num] self._screen.friends_list.takeItem(num) diff --git a/toxygen/groups/groups_service.py b/toxygen/groups/groups_service.py index 5aefe5a..c062685 100644 --- a/toxygen/groups/groups_service.py +++ b/toxygen/groups/groups_service.py @@ -46,7 +46,6 @@ class GroupsService(tox_save.ToxSave): def leave_group(self, group_number): self._tox.group_leave(group_number) self._contacts_manager.delete_group(group_number) - self._contacts_manager.update_groups_numbers() def disconnect_from_group(self, group_number): self._tox.group_disconnect(group_number) diff --git a/toxygen/middleware/callbacks.py b/toxygen/middleware/callbacks.py index 1716b49..f8300ff 100644 --- a/toxygen/middleware/callbacks.py +++ b/toxygen/middleware/callbacks.py @@ -417,11 +417,12 @@ def group_invite(window, settings, tray, profile, groups_service, contacts_provi return wrapped -def group_self_join(contacts_provider, groups_service): +def group_self_join(contacts_provider, contacts_manager, groups_service): def wrapped(tox, group_number, user_data): group = contacts_provider.get_group_by_number(group_number) invoke_in_main_thread(group.set_status, TOX_USER_STATUS['NONE']) invoke_in_main_thread(groups_service.update_group_info, group) + invoke_in_main_thread(contacts_manager.update_filtration) return wrapped @@ -565,7 +566,7 @@ def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager, tox.callback_group_message(group_message(main_window, tray, tox, messenger, settings, profile), 0) tox.callback_group_private_message(group_private_message(main_window, tray, tox, messenger, settings, profile), 0) tox.callback_group_invite(group_invite(main_window, settings, tray, profile, groups_service, contacts_provider), 0) - tox.callback_group_self_join(group_self_join(contacts_provider, groups_service), 0) + tox.callback_group_self_join(group_self_join(contacts_provider, contacts_manager, groups_service), 0) tox.callback_group_peer_join(group_peer_join(contacts_provider, groups_service), 0) tox.callback_group_peer_exit(group_peer_exit(contacts_provider, groups_service, contacts_manager), 0) tox.callback_group_peer_name(group_peer_name(contacts_provider, groups_service), 0) diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index d57667b..54b6804 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -244,7 +244,7 @@ class MainWindow(QtWidgets.QMainWindow): self.name.mouseReleaseEvent = self.profile_settings self.friends_list = left_column.friendsListWidget - self.friends_list.clicked.connect(self._friend_click) + self.friends_list.itemSelectionChanged.connect(self._selected_contact_changed) self.friends_list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.friends_list.customContextMenuRequested.connect(self._friend_right_click) self.friends_list.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel) @@ -669,12 +669,15 @@ class MainWindow(QtWidgets.QMainWindow): def invite_friend_to_gc(self, friend_number, group_number): self._contacts_manager.invite_friend(friend_number, group_number) + def select_contact_row(self, row_index): + self.friends_list.setCurrentRow(row_index) + # ----------------------------------------------------------------------------------------------------------------- # Functions which called when user click somewhere else # ----------------------------------------------------------------------------------------------------------------- - def _friend_click(self, index): - num = index.row() + def _selected_contact_changed(self): + num = self.friends_list.currentRow() self._contacts_manager.active_contact = num self.groupMenuButton.setVisible(not self._contacts_manager.is_active_a_friend())