diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 15 | ||||
-rw-r--r-- | toxcore/Messenger.h | 4 | ||||
-rw-r--r-- | toxcore/tox.c | 7 | ||||
-rw-r--r-- | toxcore/tox.h | 3 |
4 files changed, 28 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. */ | ||
2371 | uint32_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. |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index e09b2f30..40e857d1 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -178,6 +178,7 @@ typedef struct Messenger { | |||
178 | 178 | ||
179 | Friend *friendlist; | 179 | Friend *friendlist; |
180 | uint32_t numfriends; | 180 | uint32_t numfriends; |
181 | uint32_t numonline_friends; | ||
181 | 182 | ||
182 | Group_Chat **chats; | 183 | Group_Chat **chats; |
183 | uint32_t numchats; | 184 | uint32_t numchats; |
@@ -682,6 +683,9 @@ int messenger_load_encrypted(Messenger *m, uint8_t *data, uint32_t length, uint8 | |||
682 | * for copy_friendlist. */ | 683 | * for copy_friendlist. */ |
683 | uint32_t count_friendlist(Messenger *m); | 684 | uint32_t count_friendlist(Messenger *m); |
684 | 685 | ||
686 | /* Return the number of online friends in the instance m. */ | ||
687 | uint32_t get_num_online_friends(Messenger *m); | ||
688 | |||
685 | /* Copy a list of valid friend IDs into the array out_list. | 689 | /* Copy a list of valid friend IDs into the array out_list. |
686 | * If out_list is NULL, returns 0. | 690 | * If out_list is NULL, returns 0. |
687 | * Otherwise, returns the number of elements copied. | 691 | * Otherwise, returns the number of elements copied. |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 04e412be..f4690080 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -289,6 +289,13 @@ uint32_t tox_count_friendlist(Tox *tox) | |||
289 | return count_friendlist(m); | 289 | return count_friendlist(m); |
290 | } | 290 | } |
291 | 291 | ||
292 | /* Return the number of online friends in the instance m. */ | ||
293 | uint32_t tox_get_num_online_friends(Tox *tox) | ||
294 | { | ||
295 | Messenger *m = tox; | ||
296 | return get_num_online_friends(m); | ||
297 | } | ||
298 | |||
292 | /* Copy a list of valid friend IDs into the array out_list. | 299 | /* Copy a list of valid friend IDs into the array out_list. |
293 | * If out_list is NULL, returns 0. | 300 | * If out_list is NULL, returns 0. |
294 | * Otherwise, returns the number of elements copied. | 301 | * Otherwise, returns the number of elements copied. |
diff --git a/toxcore/tox.h b/toxcore/tox.h index f3118270..0597c435 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -284,6 +284,9 @@ void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno); | |||
284 | * for copy_friendlist. */ | 284 | * for copy_friendlist. */ |
285 | uint32_t tox_count_friendlist(Tox *tox); | 285 | uint32_t tox_count_friendlist(Tox *tox); |
286 | 286 | ||
287 | /* Return the number of online friends in the instance m. */ | ||
288 | uint32_t tox_get_num_online_friends(Tox *tox); | ||
289 | |||
287 | /* Copy a list of valid friend IDs into the array out_list. | 290 | /* Copy a list of valid friend IDs into the array out_list. |
288 | * If out_list is NULL, returns 0. | 291 | * If out_list is NULL, returns 0. |
289 | * Otherwise, returns the number of elements copied. | 292 | * Otherwise, returns the number of elements copied. |