more callbacks, fixes, peers
This commit is contained in:
parent
f775203f4c
commit
4abd72e278
5 changed files with 60 additions and 12 deletions
|
@ -29,7 +29,7 @@ class BaseContact:
|
|||
self.load_avatar()
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# name - current name or alias of user
|
||||
# Name - current name or alias of user
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def get_name(self):
|
||||
|
@ -43,7 +43,7 @@ class BaseContact:
|
|||
name = property(get_name, set_name)
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Status message
|
||||
# Status message or group topic
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def get_status_message(self):
|
||||
|
|
|
@ -317,6 +317,19 @@ def group_invite(tox, friend_number, invite_data, length, user_data):
|
|||
invite_data[:length])
|
||||
|
||||
|
||||
def group_self_join(tox, group_number, user_data):
|
||||
pr = Profile.get_instance()
|
||||
gc = pr.get_gc_by_number(group_number)
|
||||
invoke_in_main_thread(gc.set_status, TOX_USER_STATUS['NONE'])
|
||||
if not pr.is_active_a_friend() and pr.get_active_number() == group_number:
|
||||
invoke_in_main_thread(pr.set_active)
|
||||
|
||||
|
||||
def group_peer_join(tox, group_number, peer_id, user_data):
|
||||
gc = Profile.get_instance().get_gc_by_number(group_number)
|
||||
gc.add_peer(peer_id)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Callbacks - initialization
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -355,4 +368,6 @@ def init_callbacks(tox, window, tray):
|
|||
|
||||
tox.callback_group_message(group_message(window, tray, tox), 0)
|
||||
tox.callback_group_invite(group_invite, 0)
|
||||
tox.callback_group_self_join(group_self_join, 0)
|
||||
tox.callback_group_peer_join(group_peer_join, 0)
|
||||
|
||||
|
|
|
@ -10,4 +10,26 @@ class GroupChat(contact.Contact):
|
|||
def load_avatar(self, default_path='group.png'):
|
||||
super().load_avatar(default_path)
|
||||
|
||||
# TODO: get peers list and add other methods
|
||||
def set_status(self, value):
|
||||
print('In gc set_status')
|
||||
self.name = self._tox.group_get_name(self._number)
|
||||
self._tox_id = self._tox.group_get_chat_id(self._number)
|
||||
self.status_message = self._tox.group_get_topic(self._number)
|
||||
|
||||
def add_peer(self, peer_id):
|
||||
print(peer_id)
|
||||
print(self._tox.group_peer_get_name(self._number, peer_id))
|
||||
|
||||
# TODO: get peers list and add other methods
|
||||
|
||||
def get_peers_list(self):
|
||||
return []
|
||||
|
||||
|
||||
class Peer:
|
||||
|
||||
def __init__(self, peer_id, name, status, role):
|
||||
self._data = (peer_id, name, status, role)
|
||||
|
||||
def get_data(self):
|
||||
return self._data
|
||||
|
|
|
@ -720,7 +720,7 @@ class Profile(basecontact.BaseContact, Singleton):
|
|||
if not is_gc:
|
||||
self._tox.friend_delete(friend.number)
|
||||
else:
|
||||
self._tox.group_leave(num, message)
|
||||
self._tox.group_leave(num, message.encode('utf-8') if message is not None else None)
|
||||
del self._friends_and_gc[num]
|
||||
self._screen.friends_list.takeItem(num)
|
||||
if num == self._active_friend_or_gc: # active friend or gc was deleted
|
||||
|
|
|
@ -1607,9 +1607,11 @@ class Tox:
|
|||
"""
|
||||
|
||||
error = c_int()
|
||||
result = Tox.libtoxcore.tox_group_leave(self._tox_pointer, groupnumber, message,
|
||||
len(message) if message is not None else 0, byref(error))
|
||||
return result
|
||||
f = Tox.libtoxcore.tox_group_leave
|
||||
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
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Group user-visible client information (nickname/status/role/public key)
|
||||
|
@ -1965,7 +1967,7 @@ class Tox:
|
|||
|
||||
see the `Group chat founder controls` section for the respective set function.
|
||||
|
||||
:return true on success.
|
||||
:return password
|
||||
"""
|
||||
|
||||
error = c_int()
|
||||
|
@ -2165,10 +2167,10 @@ class Tox:
|
|||
"""
|
||||
|
||||
error = c_int()
|
||||
result = Tox.libtoxcore.tox_group_invite_accept(self._tox_pointer, invite_data, len(invite_data),
|
||||
password,
|
||||
len(password) if password is not None else 0,
|
||||
byref(error))
|
||||
f = Tox.libtoxcore.tox_group_invite_accept
|
||||
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))
|
||||
return result
|
||||
|
||||
def callback_group_invite(self, callback, user_data):
|
||||
|
@ -2195,6 +2197,11 @@ class Tox:
|
|||
Set the callback for the `group_peer_join` event. Pass NULL to unset.
|
||||
|
||||
This event is triggered when a peer other than self joins the group.
|
||||
Callback: python function with params:
|
||||
tox - Tox*
|
||||
group_number - group number
|
||||
peer_id - peer id
|
||||
user_data - user data
|
||||
"""
|
||||
|
||||
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_void_p)
|
||||
|
@ -2218,6 +2225,10 @@ class Tox:
|
|||
|
||||
This event is triggered when the client has successfully joined a group. Use this to initialize
|
||||
any group information the client may need.
|
||||
Callback: python fucntion with params:
|
||||
tox - *Tox
|
||||
group_number - group number
|
||||
user_data - user data
|
||||
"""
|
||||
|
||||
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_void_p)
|
||||
|
|
Loading…
Reference in a new issue