summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@tox.im>2014-02-08 08:46:08 -0500
committerirungentoo <irungentoo@tox.im>2014-02-08 08:46:08 -0500
commite0e48a876e74f8128183b10cd7f777078d0f0ca1 (patch)
tree5b261973921b95e6f552fa3db8b7d1cc034723e0 /toxcore/Messenger.c
parent696a6ba02e47a797b4efad9974405afc17350558 (diff)
parent8b91493e3214e38ea146d301435813f1d994f08e (diff)
Merge pull request #717 from JFreegman/master
added API function to get online friend count
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index c1301767..3b09baa2 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -273,6 +273,9 @@ int m_delfriend(Messenger *m, int friendnumber)
273 if (friend_not_valid(m, friendnumber)) 273 if (friend_not_valid(m, friendnumber))
274 return -1; 274 return -1;
275 275
276 if (m->friendlist[friendnumber].status == FRIEND_ONLINE)
277 --m->numonline_friends;
278
276 onion_delfriend(m->onion_c, m->friendlist[friendnumber].onion_friendnum); 279 onion_delfriend(m->onion_c, m->friendlist[friendnumber].onion_friendnum);
277 crypto_kill(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id); 280 crypto_kill(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id);
278 free(m->friendlist[friendnumber].statusmessage); 281 free(m->friendlist[friendnumber].statusmessage);
@@ -665,8 +668,12 @@ static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_
665 onion_set_friend_online(m->onion_c, m->friendlist[friendnumber].onion_friendnum, is_online); 668 onion_set_friend_online(m->onion_c, m->friendlist[friendnumber].onion_friendnum, is_online);
666 669
667 if (is_online != was_online) { 670 if (is_online != was_online) {
668 if (was_online) 671 if (was_online) {
669 break_files(m, friendnumber); 672 break_files(m, friendnumber);
673 --m->numonline_friends;
674 } else {
675 ++m->numonline_friends;
676 }
670 677
671 m->friend_connectionstatuschange(m, friendnumber, is_online, m->friend_connectionstatuschange_userdata); 678 m->friend_connectionstatuschange(m, friendnumber, is_online, m->friend_connectionstatuschange_userdata);
672 } 679 }
@@ -2360,6 +2367,12 @@ uint32_t count_friendlist(Messenger *m)
2360 return ret; 2367 return ret;
2361} 2368}
2362 2369
2370/* Return the number of online friends in the instance m. */
2371uint32_t get_num_online_friends(Messenger *m)
2372{
2373 return m->numonline_friends;
2374}
2375
2363/* Copy a list of valid friend IDs into the array out_list. 2376/* Copy a list of valid friend IDs into the array out_list.
2364 * If out_list is NULL, returns 0. 2377 * If out_list is NULL, returns 0.
2365 * Otherwise, returns the number of elements copied. 2378 * Otherwise, returns the number of elements copied.