diff --git a/toxcore/group.c b/toxcore/group.c index 84d7d2bb..b4aed658 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -1630,21 +1630,21 @@ void kill_groupchats(Group_Chats *g_c) /* Return the number of chats in the instance m. * You should use this to determine how much memory to allocate - * for copy_chatlist. */ -/* -uint32_t count_chatlist(const Messenger *m) + * for copy_chatlist. + */ +uint32_t count_chatlist(Group_Chats *g_c) { uint32_t ret = 0; uint32_t i; - for (i = 0; i < m->numchats; i++) { - if (m->chats[i]) { + for (i = 0; i < g_c->num_chats; i++) { + if (g_c->chats[i].status != GROUPCHAT_STATUS_NONE) { ret++; } } return ret; -}*/ +} /* Copy a list of valid chat IDs into the array out_list. * If out_list is NULL, returns 0. diff --git a/toxcore/group.h b/toxcore/group.h index 2bd3702b..8d255480 100644 --- a/toxcore/group.h +++ b/toxcore/group.h @@ -203,6 +203,12 @@ int group_number_peers(const Group_Chats *g_c, int groupnumber); int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAME_LENGTH], uint16_t lengths[], uint16_t length); +/* Return the number of chats in the instance m. + * You should use this to determine how much memory to allocate + * for copy_chatlist. + */ +uint32_t count_chatlist(Group_Chats *g_c); + /* Send current name (set in messenger) to all online groups. */ void send_name_all_groups(Group_Chats *g_c); diff --git a/toxcore/tox.c b/toxcore/tox.c index 98418d84..ee625907 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -704,8 +704,7 @@ int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX uint32_t tox_count_chatlist(const Tox *tox) { const Messenger *m = tox; - //return count_chatlist(m); - return 0; + return count_chatlist(m->group_chat_object); } /* Copy a list of valid chat IDs into the array out_list.