mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #559 from jin-eld/friendlist
Function for retreiving a list of friend numbers
This commit is contained in:
commit
c78b2352ab
|
@ -1052,3 +1052,37 @@ int Messenger_load(Messenger *m, uint8_t *data, uint32_t length)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Allocate and return a list of valid friend id's. List must be freed by the
|
||||
* caller.
|
||||
*
|
||||
* retun 0 if success.
|
||||
* return -1 if failure.
|
||||
*/
|
||||
int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
*out_list_length = 0;
|
||||
|
||||
if (m->numfriends == 0) {
|
||||
*out_list = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out_list = malloc(m->numfriends * sizeof(int));
|
||||
|
||||
if (*out_list == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < m->numfriends; i++) {
|
||||
if (m->friendlist[i].status > 0) {
|
||||
(*out_list)[i] = i;
|
||||
(*out_list_length)++;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -377,5 +377,12 @@ void Messenger_save(Messenger *m, uint8_t *data);
|
|||
/* Load the messenger from data of size length. */
|
||||
int Messenger_load(Messenger *m, uint8_t *data, uint32_t length);
|
||||
|
||||
/* Allocate and return a list of valid friend id's. List must be freed by the
|
||||
* caller.
|
||||
*
|
||||
* retun 0 if success.
|
||||
* return -1 if failure.
|
||||
*/
|
||||
int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -247,6 +247,17 @@ void tox_set_sends_receipts(void *tox, int friendnumber, int yesno)
|
|||
m_set_sends_receipts(m, friendnumber, yesno);
|
||||
}
|
||||
|
||||
/* Allocate and return a list of valid friend id's. List must be freed by the
|
||||
* caller.
|
||||
*
|
||||
* retun 0 if success.
|
||||
* return -1 if failure.
|
||||
*/
|
||||
int tox_get_friendlist(void *tox, int **out_list, uint32_t *out_list_length)
|
||||
{
|
||||
Messenger *m = tox;
|
||||
return get_friendlist(m, out_list, out_list_length);
|
||||
}
|
||||
|
||||
/* Set the function that will be executed when a friend request is received.
|
||||
* Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
|
||||
|
|
|
@ -221,6 +221,14 @@ TOX_USERSTATUS tox_get_selfuserstatus(Tox *tox);
|
|||
*/
|
||||
void tox_set_sends_receipts(Tox *tox, int friendnumber, int yesno);
|
||||
|
||||
/* Allocate and return a list of valid friend id's. List must be freed by the
|
||||
* caller.
|
||||
*
|
||||
* retun 0 if success.
|
||||
* return -1 if failure.
|
||||
*/
|
||||
int tox_get_friendlist(void *tox, int **out_list, uint32_t *out_list_length);
|
||||
|
||||
/* Set the function that will be executed when a friend request is received.
|
||||
* Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length)
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue
Block a user