diff options
author | Jman012 <jman012guy@gmail.com> | 2013-11-18 20:05:35 -0800 |
---|---|---|
committer | Jman012 <jman012guy@gmail.com> | 2013-11-18 20:05:35 -0800 |
commit | 37d97288306faefa193c1f6347665c8f58da6534 (patch) | |
tree | 6b6c93c25023b2af4b0f2b89335503f2616e6a86 /toxcore/Messenger.c | |
parent | cdfe09d221490f15150881b59a345c6e19957483 (diff) |
Added functions tox_count_chatlist and tox_copy_chatlist.
These functions are akin to the tox_count_friendlist and tox_copy_friendlist, made available on the public API.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 44 |
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. */ | ||
2181 | uint32_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. */ | ||
2198 | uint32_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 | |||