commit de9d546

violette  ·  2026-01-12 05:03:04 +0000 UTC
parent 1811323
Added emoji categories.
4 files changed,  +44, -11
M snac.h
+1, -1
1@@ -1611,7 +1611,7 @@ xs_dict *msg_emoji_init(snac *snac, const char *mid, const char *eid_o)
2     xs *dict = xs_dict_new();
3     xs *icon = xs_dict_new();
4     xs *accounts = xs_list_new();
5-    xs *emjs = emojis();
6+    xs *emjs = emojis_rm_categories();
7 
8     /* may be a default emoji */
9     xs *eidd = xs_dup(eid);
+19, -1
 1@@ -79,6 +79,24 @@ xs_dict *emojis(void)
 2     return d;
 3 }
 4 
 5+
 6+xs_dict *emojis_rm_categories() {
 7+    xs *emjs = emojis();
 8+    char *res = xs_dict_new();
 9+    const char *k, *v;
10+    xs_dict_foreach(emjs, k, v) {
11+        if (xs_type(v) == XSTYPE_DICT) {
12+            const char *v2;
13+            xs_dict_foreach(v, k, v2)
14+                res = xs_dict_append(res, k, v2);
15+        }
16+        else
17+            res = xs_dict_append(res, k, v);
18+    }
19+    return res;
20+}
21+
22+
23 /* Non-whitespace without trailing comma, period or closing paren */
24 #define NOSPACE "([^[:space:],.)]+|[,.)]+[^[:space:],.)])+"
25 
26@@ -405,7 +423,7 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag
27 
28     {
29         /* traditional emoticons */
30-        xs *d = emojis();
31+        xs *d = emojis_rm_categories();
32         int c = 0;
33         const char *k, *v;
34 
+23, -9
 1@@ -2647,19 +2647,33 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2     if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/
 3         xs *emo = emojis();
 4         xs *list = xs_list_new();
 5-        int c = 0;
 6         const xs_str *k;
 7         const xs_val *v;
 8-        while(xs_dict_next(emo, &k, &v, &c)) {
 9+        xs_dict_foreach(emo, k, v) {
10             xs *current = xs_dict_new();
11-            if (xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) {
12+            if ((xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) || xs_type(v) == XSTYPE_DICT) {
13                 /* remove first and last colon */
14-                xs *shortcode = xs_replace(k, ":", "");
15-                current = xs_dict_append(current, "shortcode", shortcode);
16-                current = xs_dict_append(current, "url", v);
17-                current = xs_dict_append(current, "static_url", v);
18-                current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE));
19-                list = xs_list_append(list, current);
20+                if (xs_type(v) == XSTYPE_DICT) {
21+                    const char *v2;
22+                    const char *cat = k;
23+                    xs_dict_foreach(v, k, v2) {
24+                        xs *shortcode = xs_replace(k, ":", "");
25+                        current = xs_dict_append(current, "shortcode", shortcode);
26+                        current = xs_dict_append(current, "url", v2);
27+                        current = xs_dict_append(current, "static_url", v2);
28+                        current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE));
29+                        current = xs_dict_append(current, "category", cat);
30+                        list = xs_list_append(list, current);
31+                    }
32+                }
33+                else {
34+                    xs *shortcode = xs_replace(k, ":", "");
35+                    current = xs_dict_append(current, "shortcode", shortcode);
36+                    current = xs_dict_append(current, "url", v);
37+                    current = xs_dict_append(current, "static_url", v);
38+                    current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE));
39+                    list = xs_list_append(list, current);
40+                }
41             }
42         }
43         *body  = xs_json_dumps(list, 0);
M snac.h
+1, -0
1@@ -412,6 +412,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
2                              char **body, int *b_size, char **ctype);
3 
4 xs_dict *emojis(void);
5+xs_dict *emojis_rm_categories(void);
6 xs_str *format_text_with_emoji(snac *user, const char *text, int ems, const char *proxy);
7 xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag);
8 xs_str *sanitize(const char *content);