Merge pull request #717 from JFreegman/master

added API function to get online friend count
This commit is contained in:
irungentoo 2014-02-08 08:46:08 -05:00
commit e0e48a876e
4 changed files with 28 additions and 1 deletions

View File

@ -273,6 +273,9 @@ int m_delfriend(Messenger *m, int friendnumber)
if (friend_not_valid(m, friendnumber))
return -1;
if (m->friendlist[friendnumber].status == FRIEND_ONLINE)
--m->numonline_friends;
onion_delfriend(m->onion_c, m->friendlist[friendnumber].onion_friendnum);
crypto_kill(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id);
free(m->friendlist[friendnumber].statusmessage);
@ -665,8 +668,12 @@ static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_
onion_set_friend_online(m->onion_c, m->friendlist[friendnumber].onion_friendnum, is_online);
if (is_online != was_online) {
if (was_online)
if (was_online) {
break_files(m, friendnumber);
--m->numonline_friends;
} else {
++m->numonline_friends;
}
m->friend_connectionstatuschange(m, friendnumber, is_online, m->friend_connectionstatuschange_userdata);
}
@ -2360,6 +2367,12 @@ uint32_t count_friendlist(Messenger *m)
return ret;
}
/* Return the number of online friends in the instance m. */
uint32_t get_num_online_friends(Messenger *m)
{
return m->numonline_friends;
}
/* Copy a list of valid friend IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.

View File

@ -178,6 +178,7 @@ typedef struct Messenger {
Friend *friendlist;
uint32_t numfriends;
uint32_t numonline_friends;
Group_Chat **chats;
uint32_t numchats;
@ -682,6 +683,9 @@ int messenger_load_encrypted(Messenger *m, uint8_t *data, uint32_t length, uint8
* for copy_friendlist. */
uint32_t count_friendlist(Messenger *m);
/* Return the number of online friends in the instance m. */
uint32_t get_num_online_friends(Messenger *m);
/* Copy a list of valid friend IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.

View File

@ -289,6 +289,13 @@ uint32_t tox_count_friendlist(Tox *tox)
return count_friendlist(m);
}
/* Return the number of online friends in the instance m. */
uint32_t tox_get_num_online_friends(Tox *tox)
{
Messenger *m = tox;
return get_num_online_friends(m);
}
/* Copy a list of valid friend IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.

View File

@ -284,6 +284,9 @@ void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno);
* for copy_friendlist. */
uint32_t tox_count_friendlist(Tox *tox);
/* Return the number of online friends in the instance m. */
uint32_t tox_get_num_online_friends(Tox *tox);
/* Copy a list of valid friend IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.