From 44a9375f2c4c9017c8ef657ea1fb79f287791c31 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 15 Oct 2014 00:51:45 -0400 Subject: [PATCH] re-implement copy_chatlist function --- toxcore/group.c | 22 ++++++++++------------ toxcore/group.h | 7 +++++++ toxcore/tox.c | 5 ++--- toxcore/tox.h | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/toxcore/group.c b/toxcore/group.c index eb84703d..9fafd8fc 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -1670,25 +1670,24 @@ uint32_t count_chatlist(Group_Chats *g_c) * 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(const Messenger *m, int *out_list, uint32_t list_size) +uint32_t copy_chatlist(Group_Chats *g_c, int32_t *out_list, uint32_t list_size) { - if (!out_list) - return 0; - - if (m->numchats == 0) { + if (!out_list) { return 0; } - uint32_t i; - uint32_t ret = 0; + if (g_c->num_chats == 0) { + return 0; + } - for (i = 0; i < m->numchats; i++) { + uint32_t i, ret = 0; + + for (i = 0; i < g_c->num_chats; ++i) { if (ret >= list_size) { - break; *//* Abandon ship *//* + break; /* Abandon ship */ } - if (m->chats[i]) { + if (g_c->chats[i].status > GROUPCHAT_STATUS_NONE) { out_list[ret] = i; ret++; } @@ -1696,4 +1695,3 @@ uint32_t copy_chatlist(const Messenger *m, int *out_list, uint32_t list_size) return ret; } -*/ diff --git a/toxcore/group.h b/toxcore/group.h index d4c77f49..3764bf94 100644 --- a/toxcore/group.h +++ b/toxcore/group.h @@ -214,6 +214,13 @@ int group_names(const Group_Chats *g_c, int groupnumber, uint8_t names[][MAX_NAM */ uint32_t count_chatlist(Group_Chats *g_c); +/* 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(Group_Chats *g_c, int32_t *out_list, uint32_t list_size); + /* 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 ea8c68ba..19146744 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -723,11 +723,10 @@ uint32_t tox_count_chatlist(const Tox *tox) * 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_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size) +uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size) { const Messenger *m = tox; - //return copy_chatlist(m, out_list, list_size); - return 0; + return copy_chatlist(m->group_chat_object, out_list, list_size); } diff --git a/toxcore/tox.h b/toxcore/tox.h index db68fff2..4920853e 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -537,7 +537,7 @@ uint32_t tox_count_chatlist(const Tox *tox); * 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_get_chatlist(const Tox *tox, int *out_list, uint32_t list_size); +uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size); /****************AVATAR FUNCTIONS*****************/