From e9f3477d693bf52750395c462788aff161d0430c Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Fri, 7 Feb 2014 19:43:21 -0500 Subject: added API function to get online friend count --- toxcore/Messenger.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'toxcore/Messenger.c') diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index c1301767..f0415501 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -665,8 +665,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 +2364,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. -- cgit v1.2.3 From 8b91493e3214e38ea146d301435813f1d994f08e Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Fri, 7 Feb 2014 20:11:36 -0500 Subject: decrement counter on friend delete --- toxcore/Messenger.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'toxcore/Messenger.c') diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index f0415501..3b09baa2 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -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); -- cgit v1.2.3