Added functions tox_count_chatlist and tox_copy_chatlist.

These functions are akin to the tox_count_friendlist and tox_copy_friendlist, made available on the public API.
This commit is contained in:
Jman012 2013-11-18 20:05:35 -08:00
parent cdfe09d221
commit 37d9728830
4 changed files with 87 additions and 0 deletions

View File

@ -2175,3 +2175,47 @@ int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length)
return 0;
}
/* Return the number of chat in the instance m.
* You should use this to determine how much memory to allocate
* for copy_grouplist. */
uint32_t count_chatlist(Messenger *m)
{
uint32_t ret = 0;
uint32_t i;
for (i = 0; i < m->numchats; i++) {
ret++;
}
return ret;
}
/* Copy a list of valid chat IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t copy_chatlist(Messenger *m, int *out_list, uint32_t list_size)
{
if (!out_list)
return 0;
if (m->numchats == 0) {
return 0;
}
uint32_t i;
uint32_t ret = 0;
for (i = 0; i < m->numchats; i++) {
if (i >= list_size) {
break; /* Abandon ship */
}
out_list[i] = i;
ret++;
}
return ret;
}

View File

@ -633,5 +633,17 @@ uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size);
*/
int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length);
/* Return the number of chats in the instance m.
* You should use this to determine how much memory to allocate
* for copy_grouplist. */
uint32_t count_chatlist(Messenger *m);
/* Copy a list of valid chat IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t copy_chatlist(Messenger *m, int *out_list, uint32_t list_size);
#endif

View File

@ -477,6 +477,25 @@ int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t
return group_message_send(m, groupnumber, message, length);
}
/* Return the number of chats in the instance m.
* You should use this to determine how much memory to allocate
* for copy_friendlist. */
uint32_t tox_count_chatlist(Tox *tox)
{
Messenger *m = tox;
return count_chatlist(m);
}
/* Copy a list of valid chat IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t tox_copy_chatlist(Tox *tox, int *out_list, uint32_t list_size)
{
Messenger *m = tox;
return copy_chatlist(m, out_list, list_size);
}
/****************FILE SENDING FUNCTIONS*****************/

View File

@ -404,6 +404,18 @@ int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_
* return -1 on failure
*/
int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length);
/* Return the number of chats in the instance m.
* You should use this to determine how much memory to allocate
* for copy_friendlist. */
uint32_t tox_count_chatlist(Tox *tox);
/* Copy a list of valid chat IDs into the array out_list.
* If out_list is NULL, returns 0.
* Otherwise, returns the number of elements copied.
* If the array was too small, the contents
* of out_list will be truncated to list_size. */
uint32_t tox_copy_chatlist(Tox *tox, int *out_list, uint32_t list_size);
/****************FILE SENDING FUNCTIONS*****************/