From 2745caa5316acee436dcf3abdc2c7f3f20243393 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 15 Jul 2016 12:12:06 +0300 Subject: [PATCH] invite fix --- toxygen/callbacks.py | 2 +- toxygen/groupchat.py | 5 +++-- toxygen/profile.py | 11 ++++++++--- toxygen/tox.py | 10 +++++----- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/toxygen/callbacks.py b/toxygen/callbacks.py index f763604..72eeb66 100644 --- a/toxygen/callbacks.py +++ b/toxygen/callbacks.py @@ -314,7 +314,7 @@ def group_message(window, tray, tox): def group_invite(tox, friend_number, invite_data, length, user_data): invoke_in_main_thread(Profile.get_instance().process_group_invite, friend_number, - invite_data[:length]) + bytes(invite_data[:length])) def group_self_join(tox, group_number, user_data): diff --git a/toxygen/groupchat.py b/toxygen/groupchat.py index 3437696..b692761 100644 --- a/toxygen/groupchat.py +++ b/toxygen/groupchat.py @@ -12,9 +12,10 @@ class GroupChat(contact.Contact): def set_status(self, value): print('In gc set_status') - self.name = self._tox.group_get_name(self._number) + super().set_status(value) + self.name = bytes(self._tox.group_get_name(self._number), 'utf-8') self._tox_id = self._tox.group_get_chat_id(self._number) - self.status_message = self._tox.group_get_topic(self._number) + self.status_message = bytes(self._tox.group_get_topic(self._number), 'utf-8') def add_peer(self, peer_id): print(peer_id) diff --git a/toxygen/profile.py b/toxygen/profile.py index a27a9e7..f1ed62b 100644 --- a/toxygen/profile.py +++ b/toxygen/profile.py @@ -1262,9 +1262,12 @@ class Profile(basecontact.BaseContact, Singleton): return list(filter(lambda x: type(x) is GroupChat, self._friends_and_gc)) def add_gc(self, num): - tox_id = self._tox.group_get_chat_id(num) - name = self._tox.group_get_name(num) - topic = self._tox.group_get_topic(num) + try: + tox_id = self._tox.group_get_chat_id(num) + name = self._tox.group_get_name(num) + topic = self._tox.group_get_topic(num) + except: + tox_id = name = topic = '' item = self.create_friend_item() try: if not self._history.friend_exists_in_db(tox_id): @@ -1289,6 +1292,7 @@ class Profile(basecontact.BaseContact, Singleton): if password: self._tox.group_founder_set_password(num, bytes(password, 'utf-8')) self.add_gc(num) + self.get_gc_by_number(num).set_status(TOX_USER_STATUS['NONE']) def process_group_invite(self, friend_num, data): # TODO: support password @@ -1302,6 +1306,7 @@ class Profile(basecontact.BaseContact, Singleton): num = self._tox.group_invite_accept(data) data = self._tox.get_savedata() ProfileHelper.get_instance().save_profile(data) + print('In gc invite', num) self.add_gc(num) elif reply != QtGui.QMessageBox.No: if friend_num in self._gc_invites: diff --git a/toxygen/tox.py b/toxygen/tox.py index 66b7210..a80900b 100644 --- a/toxygen/tox.py +++ b/toxygen/tox.py @@ -1549,9 +1549,7 @@ class Tox: """ error = c_int() - func = Tox.libtoxcore.tox_group_new - func.restype = c_uint32 - result = func(self._tox_pointer, privacy_state, group_name, + result = Tox.libtoxcore.tox_group_new(self._tox_pointer, privacy_state, group_name, len(group_name), byref(error)) return result @@ -1611,7 +1609,8 @@ class Tox: f.restype = c_bool result = f(self._tox_pointer, groupnumber, message, len(message) if message is not None else 0, byref(error)) - return result.value + print('In group leave. Result:', result, 'Error:', error.value) + return result # ----------------------------------------------------------------------------------------------------------------- # Group user-visible client information (nickname/status/role/public key) @@ -2171,6 +2170,7 @@ class Tox: f.restype = c_uint32 result = f(self._tox_pointer, invite_data, len(invite_data), password, len(password) if password is not None else 0, byref(error)) + print('Invite accept. Result:', result, 'Error:', error.value) return result def callback_group_invite(self, callback, user_data): @@ -2188,7 +2188,7 @@ class Tox: user_data - user data """ - c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_char_p, c_size_t, c_void_p) + c_callback = CFUNCTYPE(None, c_void_p, c_uint32, POINTER(c_uint8), c_size_t, c_void_p) self.group_invite_cb = c_callback(callback) Tox.libtoxcore.tox_callback_group_invite(self._tox_pointer, self.group_invite_cb, user_data)