Merge pull request #656 from Jman012/master

Added functions tox_count_chatlist and tox_copy_chatlist.
This commit is contained in:
irungentoo 2013-11-19 17:11:49 -08:00
commit 6b7f282c47
4 changed files with 93 additions and 2 deletions

View File

@ -2129,12 +2129,12 @@ uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size)
uint32_t ret = 0;
for (i = 0; i < m->numfriends; i++) {
if (i >= list_size) {
if (ret >= list_size) {
break; /* Abandon ship */
}
if (m->friendlist[i].status > 0) {
out_list[i] = i;
out_list[ret] = i;
ret++;
}
}
@ -2175,3 +2175,51 @@ int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length)
return 0;
}
/* 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(Messenger *m)
{
uint32_t ret = 0;
uint32_t i;
for (i = 0; i < m->numchats; i++) {
if (m->chats[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 (ret >= list_size) {
break; /* Abandon ship */
}
if (m->chats[i]) {
out_list[ret] = 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_chatlist. */
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_chatlist. */
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

@ -405,6 +405,18 @@ int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_
*/
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_chatlist. */
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*****************/
/* NOTE: This how to will be updated.