Browse Source

mastoapi: added support for /api/v1/custom_emojis (contributed by violette).

default 1 week ago
parent
commit
4913458205
3 changed files with 21 additions and 2 deletions
  1. 1 0
      format.c
  2. 1 0
      html.c
  3. 19 2
      mastoapi.c

+ 1 - 0
format.c

@@ -94,6 +94,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
             "`[^`]+`"                           "|"
             "~~[^~]+~~"                         "|"
             "\\*\\*?\\*?[^\\*]+\\*?\\*?\\*"     "|"
+            ":.+:"                              "|" //emotes
             "_[^_]+_"                           "|" //anzu
             "__[^_]+__"                         "|" //anzu
             "!\\[[^]]+\\]\\([^\\)]+\\)"         "|"

+ 1 - 0
html.c

@@ -92,6 +92,7 @@ xs_str *replace_shortnames(xs_str *s, const xs_list *tag, int ems, const char *p
                             xs_html *img = xs_html_sctag("img",
                                 xs_html_attr("loading", "lazy"),
                                 xs_html_attr("src", url),
+                                xs_html_attr("alt", n),
                                 xs_html_attr("style", style));
 
                             xs *s1 = xs_html_render(img);

+ 19 - 2
mastoapi.c

@@ -2116,8 +2116,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
     }
     else
     if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/
-        /* are you kidding me? */
-        *body  = xs_dup("[]");
+        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 *current = xs_dict_new();
+            if (xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) {
+                /* remove first and last colon */
+                char *shortcode = (char *)k;
+                shortcode[strlen(k) - 1] = '\0';
+                current = xs_dict_append(current, "shortcode", shortcode + 1);
+                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);
         *ctype = "application/json";
         status = HTTP_STATUS_OK;
     }