From 9d75853437e0911da440292445f170836f771de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=92=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Fri, 19 Feb 2016 20:25:49 +0300 Subject: [PATCH] Friend-specific state queries --- src/tox.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/tox.py b/src/tox.py index b03234f..d662cc9 100644 --- a/src/tox.py +++ b/src/tox.py @@ -420,7 +420,41 @@ class Tox(object): c_callback = tox_friend_status_cb(callback) self.libtoxcore.tox_callback_friend_status(self._tox_pointer, c_callback, c_void_p(user_data)) + def friend_get_connection_status(self, friend_number): + tox_err_friend_query = c_int() + result = self.libtoxcore.tox_friend_get_connection_status(self._tox_pointer, c_uint32(friend_number), + addressof(tox_err_friend_query)) + if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['TOX_ERR_FRIEND_QUERY_OK']: + return result + elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['TOX_ERR_FRIEND_QUERY_NULL']: + raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike' + ' the `_self_` variants of these functions, which have no effect when a parameter is' + ' NULL, these functions return an error in that case.') + elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND']: + raise ArgumentError('The friend_number did not designate a valid friend.') + def callback_friend_connection_status(self, callback, user_data): + tox_friend_connection_status_cb = CFUNCTYPE(None, c_void_p, c_uint32, c_int, c_void_p) + c_callback = tox_friend_connection_status_cb(callback) + self.libtoxcore.tox_callback_friend_connection_status(self._tox_pointer, c_callback, c_void_p(user_data)) + + def friend_get_typing(self, friend_number): + tox_err_friend_query = c_int() + result = self.libtoxcore.tox_friend_get_typing(self._tox_pointer, c_uint32(friend_number), + addressof(tox_err_friend_query)) + if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['TOX_ERR_FRIEND_QUERY_OK']: + return bool(result) + elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['TOX_ERR_FRIEND_QUERY_NULL']: + raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike' + ' the `_self_` variants of these functions, which have no effect when a parameter is' + ' NULL, these functions return an error in that case.') + elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND']: + raise ArgumentError('The friend_number did not designate a valid friend.') + + def callback_friend_typing(self, callback, user_data): + tox_friend_typing_cb = CFUNCTYPE(None, c_void_p, c_uint32, c_bool, c_void_p) + c_callback = tox_friend_typing_cb(callback) + self.libtoxcore.tox_callback_friend_typing(self._tox_pointer, c_callback, c_void_p(user_data)) # ----------------------------------------------------------------------------------------------------------------- # Sending private messages