From c037aefe9da822ca3e54ba018e5693fa71372128 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 19 Feb 2015 16:54:49 -0500 Subject: [PATCH] Typing and status functions implemented. --- toxcore/Messenger.c | 2 +- toxcore/Messenger.h | 2 +- toxcore/tox.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index fd97c33d..ced02a12 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -806,7 +806,7 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing) return 0; } -uint8_t m_get_istyping(const Messenger *m, int32_t friendnumber) +int m_get_istyping(const Messenger *m, int32_t friendnumber) { if (friend_not_valid(m, friendnumber)) return -1; diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 9a5044cd..4e709f64 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -616,7 +616,7 @@ int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing); * returns 0 if friend is not typing. * returns 1 if friend is typing. */ -uint8_t m_get_istyping(const Messenger *m, int32_t friendnumber); +int m_get_istyping(const Messenger *m, int32_t friendnumber); /* Sets whether we send read receipts for friendnumber. * This function is not lazy, and it will fail if yesno is not (0 or 1). diff --git a/toxcore/tox.c b/toxcore/tox.c index a9c7d4dd..6aaed15f 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -646,3 +646,43 @@ void tox_callback_friend_status_message(Tox *tox, tox_friend_status_message_cb * Messenger *m = tox; m_callback_statusmessage(m, function, user_data); } + +TOX_STATUS tox_friend_get_status(Tox const *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) +{ + const Messenger *m = tox; + + int ret = m_get_userstatus(m, friend_number); + + if (ret == USERSTATUS_INVALID) { + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND); + return TOX_STATUS_INVALID; + } + + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK); + return ret; +} + +void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *function, void *user_data) +{ + Messenger *m = tox; + m_callback_userstatus(m, function, user_data); +} + +bool tox_friend_get_typing(Tox const *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) +{ + const Messenger *m = tox; + int ret = m_get_istyping(m, friend_number); + if (ret == -1) { + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND); + return 0; + } + + SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK); + return !!ret; +} + +void tox_callback_friend_typing(Tox *tox, tox_friend_typing_cb *function, void *user_data) +{ + Messenger *m = tox; + m_callback_typingchange(m, function, user_data); +}