violette 6 місяців тому
батько
коміт
de9d546d70
4 змінених файлів з 44 додано та 11 видалено
  1. 1 1
      activitypub.c
  2. 19 1
      format.c
  3. 23 9
      mastoapi.c
  4. 1 0
      snac.h

+ 1 - 1
activitypub.c

@@ -1611,7 +1611,7 @@ xs_dict *msg_emoji_init(snac *snac, const char *mid, const char *eid_o)
     xs *dict = xs_dict_new();
     xs *icon = xs_dict_new();
     xs *accounts = xs_list_new();
-    xs *emjs = emojis();
+    xs *emjs = emojis_rm_categories();
 
     /* may be a default emoji */
     xs *eidd = xs_dup(eid);

+ 19 - 1
format.c

@@ -79,6 +79,24 @@ xs_dict *emojis(void)
     return d;
 }
 
+
+xs_dict *emojis_rm_categories() {
+    xs *emjs = emojis();
+    char *res = xs_dict_new();
+    const char *k, *v;
+    xs_dict_foreach(emjs, k, v) {
+        if (xs_type(v) == XSTYPE_DICT) {
+            const char *v2;
+            xs_dict_foreach(v, k, v2)
+                res = xs_dict_append(res, k, v2);
+        }
+        else
+            res = xs_dict_append(res, k, v);
+    }
+    return res;
+}
+
+
 /* Non-whitespace without trailing comma, period or closing paren */
 #define NOSPACE "([^[:space:],.)]+|[,.)]+[^[:space:],.)])+"
 
@@ -405,7 +423,7 @@ xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag
 
     {
         /* traditional emoticons */
-        xs *d = emojis();
+        xs *d = emojis_rm_categories();
         int c = 0;
         const char *k, *v;
 

+ 23 - 9
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);

+ 1 - 0
snac.h

@@ -412,6 +412,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
                              char **body, int *b_size, char **ctype);
 
 xs_dict *emojis(void);
+xs_dict *emojis_rm_categories(void);
 xs_str *format_text_with_emoji(snac *user, const char *text, int ems, const char *proxy);
 xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag);
 xs_str *sanitize(const char *content);