summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 19bd7edf..43572eff 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2175,3 +2175,47 @@ int get_friendlist(Messenger *m, int **out_list, uint32_t *out_list_length)
2175 return 0; 2175 return 0;
2176} 2176}
2177 2177
2178/* Return the number of chat in the instance m.
2179 * You should use this to determine how much memory to allocate
2180 * for copy_grouplist. */
2181uint32_t count_chatlist(Messenger *m)
2182{
2183 uint32_t ret = 0;
2184 uint32_t i;
2185
2186 for (i = 0; i < m->numchats; i++) {
2187 ret++;
2188 }
2189
2190 return ret;
2191}
2192
2193/* Copy a list of valid chat IDs into the array out_list.
2194 * If out_list is NULL, returns 0.
2195 * Otherwise, returns the number of elements copied.
2196 * If the array was too small, the contents
2197 * of out_list will be truncated to list_size. */
2198uint32_t copy_chatlist(Messenger *m, int *out_list, uint32_t list_size)
2199{
2200 if (!out_list)
2201 return 0;
2202
2203 if (m->numchats == 0) {
2204 return 0;
2205 }
2206
2207 uint32_t i;
2208 uint32_t ret = 0;
2209
2210 for (i = 0; i < m->numchats; i++) {
2211 if (i >= list_size) {
2212 break; /* Abandon ship */
2213 }
2214
2215 out_list[i] = i;
2216 ret++;
2217 }
2218
2219 return ret;
2220}
2221