From 6538cedcf2f62c260369561ace108d4bd498a584 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 19 Jul 2018 00:00:01 +0300 Subject: [PATCH] reconnect/disconnect functionality --- toxygen/app.py | 8 +++++++- toxygen/contacts/contact_menu.py | 11 +++++++++++ toxygen/contacts/contacts_manager.py | 5 ++++- toxygen/contacts/group_chat.py | 3 ++- toxygen/groups/groups_service.py | 11 +++++++++++ 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/toxygen/app.py b/toxygen/app.py index 1dd74b4..62025d9 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -338,6 +338,7 @@ class App: self._group_factory = GroupFactory(self._profile_manager, self._settings, self._tox, db, contact_items_factory) self._contacts_provider = ContactProvider(self._tox, self._friend_factory, self._group_factory) self._profile = Profile(self._profile_manager, self._tox, self._ms, self._contacts_provider, self._reset) + self._init_profile() self._plugin_loader = PluginLoader(self._settings, self) history = None messages_items_factory = MessagesItemsFactory(self._settings, self._plugin_loader, self._smiley_loader, @@ -349,7 +350,8 @@ class App: history.set_contacts_manager(self._contacts_manager) self._calls_manager = CallsManager(self._tox.AV, self._settings, self._ms, self._contacts_manager) self._messenger = Messenger(self._tox, self._plugin_loader, self._ms, self._contacts_manager, - self._contacts_provider, messages_items_factory, self._profile, self._calls_manager) + self._contacts_provider, messages_items_factory, self._profile, + self._calls_manager) file_transfers_message_service = FileTransfersMessagesService(self._contacts_manager, messages_items_factory, self._profile, self._ms) self._file_transfer_handler = FileTransfersHandler(self._tox, self._settings, self._contacts_provider, @@ -387,3 +389,7 @@ class App: callbacks.init_callbacks(self._tox, self._profile, self._settings, self._plugin_loader, self._contacts_manager, self._calls_manager, self._file_transfer_handler, self._ms, self._tray, self._messenger, self._groups_service, self._contacts_provider) + + def _init_profile(self): + if not self._profile.has_avatar(): + self._profile.reset_avatar(self._settings['identicons']) diff --git a/toxygen/contacts/contact_menu.py b/toxygen/contacts/contact_menu.py index 4a0dcaa..ff6a9ed 100644 --- a/toxygen/contacts/contact_menu.py +++ b/toxygen/contacts/contact_menu.py @@ -30,6 +30,12 @@ class ContactMenuBuilder: return self + def with_optional_action(self, text, handler, show_action): + if show_action: + self._add_action(text, handler) + + return self + def with_actions(self, actions): for action in actions: (text, handler) = action @@ -175,6 +181,11 @@ class GroupMenuGenerator(BaseContactMenuGenerator): menu = (builder .with_action(util_ui.tr('Set alias'), lambda: main_screen.set_alias(number)) .with_submenu(copy_menu_builder) + .with_action(util_ui.tr('Reconnect to group'), + lambda: groups_service.reconnect_to_group(self._contact.number)) + .with_optional_action(util_ui.tr('Disconnect from group'), + lambda: groups_service.disconnect_from_group(self._contact.number), + self._contact.status is not None) .with_action(util_ui.tr('Leave group'), lambda: groups_service.leave_group(self._contact.number)) .with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact)) ).build() diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index 5d07bd2..2729959 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -490,10 +490,13 @@ class ContactsManager(ToxSave): del self._settings['notes'][contact.tox_id] self._settings.save() self._history.delete_history(contact) + if contact.has_avatar(): + avatar_path = contact.get_contact_avatar_path() + remove(avatar_path) 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) + self.set_active(0 if len(self._contacts) > 1 else -1) 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/contacts/group_chat.py b/toxygen/contacts/group_chat.py index b7429d4..57d471a 100644 --- a/toxygen/contacts/group_chat.py +++ b/toxygen/contacts/group_chat.py @@ -11,7 +11,8 @@ class GroupChat(contact.Contact, ToxSave): def __init__(self, tox, profile_manager, message_getter, number, name, status_message, widget, tox_id): super().__init__(profile_manager, message_getter, number, name, status_message, widget, tox_id) ToxSave.__init__(self, tox) - self.set_status(constants.TOX_USER_STATUS['NONE']) + status = self._tox.group_is_connected(number) + self.set_status(constants.TOX_USER_STATUS['NONE'] if status else None) self._peers = [] self._add_self_to_gc() diff --git a/toxygen/groups/groups_service.py b/toxygen/groups/groups_service.py index 83f6a4e..69f8ec1 100644 --- a/toxygen/groups/groups_service.py +++ b/toxygen/groups/groups_service.py @@ -1,6 +1,7 @@ import common.tox_save as tox_save import utils.ui as util_ui from groups.peers_list import PeersListGenerator +import wrapper.toxcore_enums_and_consts as constants class GroupsService(tox_save.ToxSave): @@ -42,6 +43,16 @@ class GroupsService(tox_save.ToxSave): 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) + group = self._get_group(group_number) + group.status = None + + def reconnect_to_group(self, group_number): + self._tox.group_reconnect(group_number) + group = self._get_group(group_number) + group.status = constants.TOX_USER_STATUS['NONE'] + # ----------------------------------------------------------------------------------------------------------------- # Group invites # -----------------------------------------------------------------------------------------------------------------