fixed group numbers restoring. contact selection fixed

This commit is contained in:
ingvar1995 2018-07-29 13:36:16 +03:00
parent f38df24947
commit 250551e752
6 changed files with 33 additions and 27 deletions

View file

@ -327,6 +327,7 @@ class App:
self._calls_manager.set_toxav(self._tox.AV) self._calls_manager.set_toxav(self._tox.AV)
self._contacts_manager.update_friends_numbers() self._contacts_manager.update_friends_numbers()
self._contacts_manager.update_groups_lists() self._contacts_manager.update_groups_lists()
self._contacts_manager.update_groups_numbers()
self._init_callbacks() self._init_callbacks()

View file

@ -43,6 +43,7 @@ class Contact(basecontact.BaseContact):
""" """
:param first_time: friend became active, load first part of messages :param first_time: friend became active, load first part of messages
""" """
try:
if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')): if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')):
return return
if self._message_getter is None: if self._message_getter is None:
@ -54,6 +55,9 @@ class Contact(basecontact.BaseContact):
return return
data = list(map(lambda p: self._get_text_message(p), data)) data = list(map(lambda p: self._get_text_message(p), data))
self._corr = data + self._corr self._corr = data + self._corr
except:
pass
finally:
self._history_loaded = True self._history_loaded = True
def load_all_corr(self): def load_all_corr(self):

View file

@ -139,13 +139,6 @@ class ContactsManager(ToxSave):
active_contact_changed = property(get_active_contact_changed) 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): def update(self):
if self._active_contact + 1: if self._active_contact + 1:
self.set_active(self._active_contact) self.set_active(self._active_contact)
@ -309,6 +302,7 @@ class ContactsManager(ToxSave):
""" """
self._tox.friend_add_norequest(tox_id) self._tox.friend_add_norequest(tox_id)
self._add_friend(tox_id) self._add_friend(tox_id)
self.update_filtration()
def block_user(self, tox_id): def block_user(self, tox_id):
""" """
@ -351,6 +345,7 @@ class ContactsManager(ToxSave):
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.update_filtration()
def delete_group(self, group_number): def delete_group(self, group_number):
group = self.get_group_by_number(group_number) group = self.get_group_by_number(group_number)
@ -464,7 +459,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.set_active(0) self._screen.select_contact_row(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()
@ -542,7 +537,10 @@ class ContactsManager(ToxSave):
def _delete_contact(self, num): def _delete_contact(self, num):
if num == self._active_contact: # active friend was deleted 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) 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)

View file

@ -46,7 +46,6 @@ class GroupsService(tox_save.ToxSave):
def leave_group(self, group_number): def leave_group(self, group_number):
self._tox.group_leave(group_number) self._tox.group_leave(group_number)
self._contacts_manager.delete_group(group_number) self._contacts_manager.delete_group(group_number)
self._contacts_manager.update_groups_numbers()
def disconnect_from_group(self, group_number): def disconnect_from_group(self, group_number):
self._tox.group_disconnect(group_number) self._tox.group_disconnect(group_number)

View file

@ -417,11 +417,12 @@ def group_invite(window, settings, tray, profile, groups_service, contacts_provi
return wrapped 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): def wrapped(tox, group_number, user_data):
group = contacts_provider.get_group_by_number(group_number) group = contacts_provider.get_group_by_number(group_number)
invoke_in_main_thread(group.set_status, TOX_USER_STATUS['NONE']) 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(groups_service.update_group_info, group)
invoke_in_main_thread(contacts_manager.update_filtration)
return wrapped 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_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_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_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_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_exit(group_peer_exit(contacts_provider, groups_service, contacts_manager), 0)
tox.callback_group_peer_name(group_peer_name(contacts_provider, groups_service), 0) tox.callback_group_peer_name(group_peer_name(contacts_provider, groups_service), 0)

View file

@ -244,7 +244,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.name.mouseReleaseEvent = self.profile_settings self.name.mouseReleaseEvent = self.profile_settings
self.friends_list = left_column.friendsListWidget 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.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.friends_list.customContextMenuRequested.connect(self._friend_right_click) self.friends_list.customContextMenuRequested.connect(self._friend_right_click)
self.friends_list.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel) 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): def invite_friend_to_gc(self, friend_number, group_number):
self._contacts_manager.invite_friend(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 # Functions which called when user click somewhere else
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
def _friend_click(self, index): def _selected_contact_changed(self):
num = index.row() num = self.friends_list.currentRow()
self._contacts_manager.active_contact = num self._contacts_manager.active_contact = num
self.groupMenuButton.setVisible(not self._contacts_manager.is_active_a_friend()) self.groupMenuButton.setVisible(not self._contacts_manager.is_active_a_friend())