summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c52
1 files changed, 50 insertions, 2 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 19bd7edf..73a1471c 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -2129,12 +2129,12 @@ uint32_t copy_friendlist(Messenger *m, int *out_list, uint32_t list_size)
2129 uint32_t ret = 0; 2129 uint32_t ret = 0;
2130 2130
2131 for (i = 0; i < m->numfriends; i++) { 2131 for (i = 0; i < m->numfriends; i++) {
2132 if (i >= list_size) { 2132 if (ret >= list_size) {
2133 break; /* Abandon ship */ 2133 break; /* Abandon ship */
2134 } 2134 }
2135 2135
2136 if (m->friendlist[i].status > 0) { 2136 if (m->friendlist[i].status > 0) {
2137 out_list[i] = i; 2137 out_list[ret] = i;
2138 ret++; 2138 ret++;
2139 } 2139 }
2140 } 2140 }
@@ -2175,3 +2175,51 @@ 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 chats in the instance m.
2179 * You should use this to determine how much memory to allocate
2180 * for copy_chatlist. */
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 if (m->chats[i]) {
2188 ret++;
2189 }
2190 }
2191
2192 return ret;
2193}
2194
2195/* Copy a list of valid chat IDs into the array out_list.
2196 * If out_list is NULL, returns 0.
2197 * Otherwise, returns the number of elements copied.
2198 * If the array was too small, the contents
2199 * of out_list will be truncated to list_size. */
2200uint32_t copy_chatlist(Messenger *m, int *out_list, uint32_t list_size)
2201{
2202 if (!out_list)
2203 return 0;
2204
2205 if (m->numchats == 0) {
2206 return 0;
2207 }
2208
2209 uint32_t i;
2210 uint32_t ret = 0;
2211
2212 for (i = 0; i < m->numchats; i++) {
2213 if (ret >= list_size) {
2214 break; /* Abandon ship */
2215 }
2216
2217 if (m->chats[i]) {
2218 out_list[ret] = i;
2219 ret++;
2220 }
2221 }
2222
2223 return ret;
2224}
2225