From 7e08be71e05444bd4e96ae04b5acea65e44b4a7a Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 21 Jul 2018 20:25:10 +0300 Subject: [PATCH] group topic support --- toxygen/contacts/contact_menu.py | 3 +++ toxygen/contacts/group_chat.py | 6 ++++++ toxygen/groups/groups_service.py | 11 +++++++++++ toxygen/middleware/callbacks.py | 1 + toxygen/wrapper/tox.py | 1 + 5 files changed, 22 insertions(+) diff --git a/toxygen/contacts/contact_menu.py b/toxygen/contacts/contact_menu.py index ff6a9ed..6a2eb86 100644 --- a/toxygen/contacts/contact_menu.py +++ b/toxygen/contacts/contact_menu.py @@ -181,6 +181,9 @@ class GroupMenuGenerator(BaseContactMenuGenerator): menu = (builder .with_action(util_ui.tr('Set alias'), lambda: main_screen.set_alias(number)) .with_submenu(copy_menu_builder) + .with_optional_action(util_ui.tr('Set topic'), + lambda: groups_service.set_group_topic(self._contact), + self._contact.is_moderator_or_founder()) .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'), diff --git a/toxygen/contacts/group_chat.py b/toxygen/contacts/group_chat.py index b18fb14..fac2165 100644 --- a/toxygen/contacts/group_chat.py +++ b/toxygen/contacts/group_chat.py @@ -33,6 +33,12 @@ class GroupChat(contact.Contact, ToxSave): def get_self_name(self): return self._peers[0].name + def get_self_role(self): + return self._peers[0].role + + def is_moderator_or_founder(self): + return self.get_self_role() <= constants.TOX_GROUP_ROLE['MODERATOR'] + def add_peer(self, peer_id, is_current_user=False): peer = GroupChatPeer(peer_id, self._tox.group_peer_get_name(self._number, peer_id), diff --git a/toxygen/groups/groups_service.py b/toxygen/groups/groups_service.py index 2c0d4c3..1a8ccc0 100644 --- a/toxygen/groups/groups_service.py +++ b/toxygen/groups/groups_service.py @@ -76,6 +76,17 @@ class GroupsService(tox_save.ToxSave): group.name = self._tox.group_get_name(group.number) group.status_message = self._tox.group_get_topic(group.number) + def set_group_topic(self, group): + if not group.is_moderator_or_founder(): + return + text = util_ui.tr('New topic for group {}:'.format(group.name)) + title = util_ui.tr('Set group topic') + topic, ok = util_ui.text_dialog(text, title, group.status_message) + if not ok or not topic: + return + self._tox.group_set_topic(group.number, topic) + group.status_message = topic + # ----------------------------------------------------------------------------------------------------------------- # Peers list # ----------------------------------------------------------------------------------------------------------------- diff --git a/toxygen/middleware/callbacks.py b/toxygen/middleware/callbacks.py index 513cdd2..8730b54 100644 --- a/toxygen/middleware/callbacks.py +++ b/toxygen/middleware/callbacks.py @@ -399,6 +399,7 @@ def group_peer_join(contacts_provider, groups_service): group = contacts_provider.get_group_by_number(group_number) group.add_peer(peer_id) invoke_in_main_thread(groups_service.generate_peers_list) + invoke_in_main_thread(groups_service.update_group_info, group) return wrapped diff --git a/toxygen/wrapper/tox.py b/toxygen/wrapper/tox.py index fc438d8..836d38c 100644 --- a/toxygen/wrapper/tox.py +++ b/toxygen/wrapper/tox.py @@ -1851,6 +1851,7 @@ class Tox: """ error = c_int() + topic = bytes(topic, 'utf-8') result = Tox.libtoxcore.tox_group_set_topic(self._tox_pointer, group_number, topic, len(topic), byref(error)) return result