From eba7e0c0dcd38c7129c036b4929f5e5f273e53cd Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 22 Jul 2018 14:08:47 +0300 Subject: [PATCH] group peer context menu --- toxygen/contacts/contact_menu.py | 17 +++++++++++++++++ toxygen/contacts/contacts_manager.py | 6 ++++++ toxygen/contacts/group_peer_contact.py | 3 ++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/toxygen/contacts/contact_menu.py b/toxygen/contacts/contact_menu.py index 6a2eb86..e10f07d 100644 --- a/toxygen/contacts/contact_menu.py +++ b/toxygen/contacts/contact_menu.py @@ -194,3 +194,20 @@ class GroupMenuGenerator(BaseContactMenuGenerator): ).build() return menu + + +class GroupPeerMenuGenerator(BaseContactMenuGenerator): + + def generate(self, plugin_loader, contacts_manager, main_screen, settings, number, groups_service): + copy_menu_builder = self._generate_copy_menu_builder(main_screen) + + builder = ContactMenuBuilder() + 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('Quit chat'), + lambda: contacts_manager.remove_group_peer(self._contact)) + .with_action(util_ui.tr('Notes'), lambda: main_screen.show_note(self._contact)) + ).build() + + return menu diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index 6135967..5913617 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -362,6 +362,12 @@ class ContactsManager(ToxSave): contact.reset_avatar(self._settings['identicons']) self._save_profile() + def remove_group_peer(self, group_peer_contact): + contact = self.get_contact_by_tox_id(group_peer_contact.tox_id) + self._cleanup_contact_data(contact) + num = self._contacts.index(contact) + self._delete_contact(num) + # ----------------------------------------------------------------------------------------------------------------- # Friend requests # ----------------------------------------------------------------------------------------------------------------- diff --git a/toxygen/contacts/group_peer_contact.py b/toxygen/contacts/group_peer_contact.py index 47cd16b..8854198 100644 --- a/toxygen/contacts/group_peer_contact.py +++ b/toxygen/contacts/group_peer_contact.py @@ -1,4 +1,5 @@ import contacts.contact +from contacts.contact_menu import GroupPeerMenuGenerator class GroupPeerContact(contacts.contact.Contact): @@ -16,4 +17,4 @@ class GroupPeerContact(contacts.contact.Contact): pass def get_context_menu_generator(self): - return None + return GroupPeerMenuGenerator(self)