From de9d546d70cfcbf3b2450b70039470c9a68ecdc6 Mon Sep 17 00:00:00 2001 From: violette Date: Mon, 12 Jan 2026 06:03:04 +0100 Subject: Added emoji categories. --- mastoapi.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 8187115..dd80abc 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2647,19 +2647,33 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/ xs *emo = emojis(); xs *list = xs_list_new(); - int c = 0; const xs_str *k; const xs_val *v; - while(xs_dict_next(emo, &k, &v, &c)) { + xs_dict_foreach(emo, k, v) { xs *current = xs_dict_new(); - if (xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) { + if ((xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) || xs_type(v) == XSTYPE_DICT) { /* remove first and last colon */ - xs *shortcode = xs_replace(k, ":", ""); - current = xs_dict_append(current, "shortcode", shortcode); - current = xs_dict_append(current, "url", v); - current = xs_dict_append(current, "static_url", v); - current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE)); - list = xs_list_append(list, current); + if (xs_type(v) == XSTYPE_DICT) { + const char *v2; + const char *cat = k; + xs_dict_foreach(v, k, v2) { + xs *shortcode = xs_replace(k, ":", ""); + current = xs_dict_append(current, "shortcode", shortcode); + current = xs_dict_append(current, "url", v2); + current = xs_dict_append(current, "static_url", v2); + current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE)); + current = xs_dict_append(current, "category", cat); + list = xs_list_append(list, current); + } + } + else { + xs *shortcode = xs_replace(k, ":", ""); + current = xs_dict_append(current, "shortcode", shortcode); + current = xs_dict_append(current, "url", v); + current = xs_dict_append(current, "static_url", v); + current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE)); + list = xs_list_append(list, current); + } } } *body = xs_json_dumps(list, 0); -- cgit v1.2.3