From 9c129e925be6845fe817887f0514eb6d30b5f012 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 16 Jul 2017 22:51:20 +0300 Subject: [PATCH] base gc class, callbacks part1 --- toxygen/callbacks.py | 29 +++++++++++++++++++++++++++++ toxygen/group_chat.py | 19 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 toxygen/group_chat.py diff --git a/toxygen/callbacks.py b/toxygen/callbacks.py index eaf5346..31b50bd 100644 --- a/toxygen/callbacks.py +++ b/toxygen/callbacks.py @@ -374,6 +374,29 @@ def video_receive_frame(toxav, friend_number, width, height, y, u, v, ystride, u except Exception as ex: print(ex) +# ----------------------------------------------------------------------------------------------------------------- +# Callbacks - groups +# ----------------------------------------------------------------------------------------------------------------- + + +def group_invite(tox, friend_number, gc_type, data, length, user_data): + invoke_in_main_thread(Profile.get_instance().group_invite, friend_number, gc_type, data[:length]) + + +def group_message(tox, group_number, peer_number, message, length, user_data): + invoke_in_main_thread(Profile.get_instance().new_gc_message, group_number, + peer_number, TOX_MESSAGE_TYPE['NORMAL'], message[:length]) + + +def group_action(tox, group_number, peer_number, message, length, user_data): + invoke_in_main_thread(Profile.get_instance().new_gc_message, group_number, + peer_number, TOX_MESSAGE_TYPE['ACTION'], message[:length]) + + +def group_title(tox, group_number, peer_number, title, length, user_data): + invoke_in_main_thread(Profile.get_instance().new_gc_title, group_number, + title[:length]) + # ----------------------------------------------------------------------------------------------------------------- # Callbacks - initialization # ----------------------------------------------------------------------------------------------------------------- @@ -410,3 +433,9 @@ def init_callbacks(tox, window, tray): tox.callback_friend_lossless_packet(lossless_packet, 0) tox.callback_friend_lossy_packet(lossy_packet, 0) + + tox.callback_group_invite(group_invite) + tox.callback_group_message(group_message) + tox.callback_group_action(group_action) + tox.callback_group_title(group_title) + tox.callback_group_namelist_change(group_namelist_change) diff --git a/toxygen/group_chat.py b/toxygen/group_chat.py new file mode 100644 index 0000000..acf84e8 --- /dev/null +++ b/toxygen/group_chat.py @@ -0,0 +1,19 @@ +import basecontact + + +class GroupChat(basecontact.BaseContact): + + def __init__(self, name, status_message, widget, tox, group_number): + super().__init__(name, status_message, widget, None) + self._number = group_number + self._tox = tox + + def set_name(self, name): + self._tox.group_set_title(self._number, name) + super().set_name(name) + + def send_message(self, message): + self._tox.group_message_send(self._number, message.encode('utf-8')) + + def new_title(self, title): + self._name = title