Merge pull request #564 from nurupo/friendstatus-patch

Removed friendstatus from client-side API, replacing it with alternative functions
This commit is contained in:
irungentoo 2013-09-07 14:27:58 -07:00
commit 49dd40797c
5 changed files with 76 additions and 45 deletions

View File

@ -98,12 +98,22 @@ START_TEST(test_m_set_userstatus)
}
END_TEST
START_TEST(test_m_friendstatus)
START_TEST(test_m_get_friend_connectionstatus)
{
ck_assert_msg((m_friendstatus(m, -1) == NOFRIEND),
"m_friendstatus did NOT catch an argument of -1.\n");
ck_assert_msg((m_friendstatus(m, REALLY_BIG_NUMBER) == NOFRIEND),
"m_friendstatus did NOT catch an argument of %d.\n",
ck_assert_msg((m_get_friend_connectionstatus(m, -1) == -1),
"m_get_friend_connectionstatus did NOT catch an argument of -1.\n");
ck_assert_msg((m_get_friend_connectionstatus(m, REALLY_BIG_NUMBER) == -1),
"m_get_friend_connectionstatus did NOT catch an argument of %d.\n",
REALLY_BIG_NUMBER);
}
END_TEST
START_TEST(test_m_friend_exists)
{
ck_assert_msg((m_friend_exists(m, -1) == 0),
"m_friend_exists did NOT catch an argument of -1.\n");
ck_assert_msg((m_friend_exists(m, REALLY_BIG_NUMBER) == 0),
"m_friend_exists did NOT catch an argument of %d.\n",
REALLY_BIG_NUMBER);
}
END_TEST
@ -220,7 +230,8 @@ Suite *messenger_suite(void)
TCase *userstatus_size = tcase_create("userstatus_size");
TCase *set_userstatus = tcase_create("set_userstatus");
TCase *send_message = tcase_create("send_message");
TCase *friendstatus = tcase_create("friendstatus");
TCase *friend_exists = tcase_create("friend_exists");
TCase *get_friend_connectionstatus = tcase_create("get_friend_connectionstatus");
TCase *getself_name = tcase_create("getself_name");
TCase *delfriend = tcase_create("delfriend");
//TCase *addfriend = tcase_create("addfriend");
@ -229,7 +240,8 @@ Suite *messenger_suite(void)
tcase_add_test(userstatus_size, test_m_get_userstatus_size);
tcase_add_test(set_userstatus, test_m_set_userstatus);
tcase_add_test(friendstatus, test_m_friendstatus);
tcase_add_test(get_friend_connectionstatus, test_m_get_friend_connectionstatus);
tcase_add_test(friend_exists, test_m_friend_exists);
tcase_add_test(getself_name, test_getself_name);
tcase_add_test(send_message, test_m_sendmesage);
tcase_add_test(delfriend, test_m_delfriend);
@ -239,7 +251,8 @@ Suite *messenger_suite(void)
suite_add_tcase(s, userstatus_size);
suite_add_tcase(s, set_userstatus);
suite_add_tcase(s, friendstatus);
suite_add_tcase(s, get_friend_connectionstatus);
suite_add_tcase(s, friend_exists);
suite_add_tcase(s, send_message);
suite_add_tcase(s, getself_name);
suite_add_tcase(s, delfriend);

View File

@ -275,18 +275,20 @@ int m_delfriend(Messenger *m, int friendnumber)
return 0;
}
/* return FRIEND_ONLINE if friend is online.
* return FRIEND_CONFIRMED if friend is confirmed.
* return FRIEND_REQUESTED if the friend request was sent.
* return FRIEND_ADDED if the friend was added.
* return NOFRIEND if there is no friend with that number.
*/
int m_friendstatus(Messenger *m, int friendnumber)
int m_get_friend_connectionstatus(Messenger *m, int friendnumber)
{
if (friend_not_valid(m, friendnumber))
return NOFRIEND;
return -1;
return m->friendlist[friendnumber].status;
return m->friendlist[friendnumber].status == FRIEND_ONLINE;
}
int m_friend_exists(Messenger *m, int friendnumber)
{
if (friend_not_valid(m, friendnumber))
return 0;
return m->friendlist[friendnumber].status > NOFRIEND;
}
/* Send a text chat message to an online friend.

View File

@ -202,13 +202,20 @@ int getclient_id(Messenger *m, int friend_id, uint8_t *client_id);
/* Remove a friend. */
int m_delfriend(Messenger *m, int friendnumber);
/* return 4 if friend is online.
* return 3 if friend is confirmed.
* return 2 if the friend request was sent.
* return 1 if the friend was added.
* return 0 if there is no friend with that number.
/* Checks friend's connecting status.
*
* return 1 if friend is connected to us (Online).
* return 0 if friend is not connected to us (Offline).
* return -1 on failure.
*/
int m_friendstatus(Messenger *m, int friendnumber);
int m_get_friend_connectionstatus(Messenger *m, int friendnumber);
/* Checks if there exists a friend with given friendnumber.
*
* return 1 if friend exists.
* return 0 if friend doesn't exist.
*/
int m_friend_exists(Messenger *m, int friendnumber);
/* Send a text chat message to an online friend.
*

View File

@ -99,16 +99,27 @@ int tox_delfriend(void *tox, int friendnumber)
return m_delfriend(m, friendnumber);
}
/* return 4 if friend is online.
* return 3 if friend is confirmed.
* return 2 if the friend request was sent.
* return 1 if the friend was added.
* return 0 if there is no friend with that number.
/* Checks friend's connecting status.
*
* return 1 if friend is connected to us (Online).
* return 0 if friend is not connected to us (Offline).
* return -1 on failure.
*/
int tox_friendstatus(void *tox, int friendnumber)
int tox_get_friend_connectionstatus(void *tox, int friendnumber)
{
Messenger *m = tox;
return m_friendstatus(m, friendnumber);
return m_get_friend_connectionstatus(m, friendnumber);
}
/* Checks if there exists a friend with given friendnumber.
*
* return 1 if friend exists.
* return 0 if friend doesn't exist.
*/
int tox_friend_exists(void *tox, int friendnumber)
{
Messenger *m = tox;
return m_friend_exists(m, friendnumber);
}
/* Send a text chat message to an online friend.

View File

@ -50,15 +50,6 @@ typedef struct {
uint16_t padding;
} tox_IP_Port;
/* Status definitions. */
enum {
TOX_NOFRIEND,
TOX_FRIEND_ADDED,
TOX_FRIEND_REQUESTED,
TOX_FRIEND_CONFIRMED,
TOX_FRIEND_ONLINE,
};
/* Errors for m_addfriend
* FAERR - Friend Add Error
*/
@ -130,13 +121,20 @@ int tox_getclient_id(Tox *tox, int friend_id, uint8_t *client_id);
/* Remove a friend. */
int tox_delfriend(Tox *tox, int friendnumber);
/* return TOX_FRIEND_ONLINE if friend is online.
* return TOX_FRIEND_CONFIRMED if friend is confirmed.
* return TOX_FRIEND_REQUESTED if the friend request was sent.
* return TOX_FRIEND_ADDED if the friend was added.
* return TOX_NOFRIEND if there is no friend with that number.
/* Checks friend's connecting status.
*
* return 1 if friend is connected to us (Online).
* return 0 if friend is not connected to us (Offline).
* return -1 on failure.
*/
int tox_friendstatus(Tox *tox, int friendnumber);
int tox_get_friend_connectionstatus(Tox *tox, int friendnumber);
/* Checks if there exists a friend with given friendnumber.
*
* return 1 if friend exists.
* return 0 if friend doesn't exist.
*/
int tox_friend_exists(Tox *tox, int friendnumber);
/* Send a text chat message to an online friend.
*