mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #656 from Jman012/master
Added functions tox_count_chatlist and tox_copy_chatlist.
This commit is contained in:
commit
6b7f282c47
|
@ -2129,12 +2129,12 @@ uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size)
|
||||||
uint32_t ret = 0;
|
uint32_t ret = 0;
|
||||||
|
|
||||||
for (i = 0; i < m->numfriends; i++) {
|
for (i = 0; i < m->numfriends; i++) {
|
||||||
if (i >= list_size) {
|
if (ret >= list_size) {
|
||||||
break; /* Abandon ship */
|
break; /* Abandon ship */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m->friendlist[i].status > 0) {
|
if (m->friendlist[i].status > 0) {
|
||||||
out_list[i] = i;
|
out_list[ret] = i;
|
||||||
ret++;
|
ret++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2175,3 +2175,51 @@ int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length)
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -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 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*****************/
|
/****************FILE SENDING FUNCTIONS*****************/
|
||||||
|
|
|
@ -404,6 +404,18 @@ int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length);
|
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*****************/
|
/****************FILE SENDING FUNCTIONS*****************/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user