commit 9e9d740

default  ·  2023-04-10 11:22:59 +0000 UTC
parent 3fb651b
Added image attachments.
2 files changed,  +31, -4
M html.c
M html.c
+6, -3
 1@@ -332,7 +332,7 @@ d_char *html_top_controls(snac *snac, d_char *s)
 2         "<input type=\"hidden\" name=\"in_reply_to\" value=\"\">\n"
 3         "<p>%s: <input type=\"checkbox\" name=\"sensitive\">\n"
 4         "<p>%s: <input type=\"checkbox\" name=\"mentioned_only\">\n"
 5-        "<p><input type=\"file\" name=\"attach\">\n"
 6+        "<p>%s: <input type=\"file\" name=\"attach\">\n"
 7         "<p>%s: <input type=\"text\" name=\"alt_text\">\n"
 8         "<p><input type=\"submit\" class=\"button\" value=\"%s\">\n"
 9         "</form><p>\n"
10@@ -425,6 +425,7 @@ d_char *html_top_controls(snac *snac, d_char *s)
11         snac->actor,
12         L("Sensitive content"),
13         L("Only for mentioned people"),
14+        L("Image"),
15         L("Image description"),
16         L("Post"),
17 
18@@ -593,7 +594,7 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, const char *md5)
19 
20             "<p>%s: <input type=\"checkbox\" name=\"sensitive\">\n"
21             "<p>%s: <input type=\"checkbox\" name=\"mentioned_only\">\n"
22-            "<p><input type=\"file\" name=\"attach\">\n"
23+            "<p>%s: <input type=\"file\" name=\"attach\">\n"
24             "<p>%s: <input type=\"text\" name=\"alt_text\">\n"
25 
26             "<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n"
27@@ -609,6 +610,7 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, const char *md5)
28             id,
29             L("Sensitive content"),
30             L("Only for mentioned people"),
31+            L("Image"),
32             L("Image description"),
33             md5,
34             L("Post")
35@@ -632,7 +634,7 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, const char *md5)
36 
37             "<p>%s: <input type=\"checkbox\" name=\"sensitive\">\n"
38             "<p>%s: <input type=\"checkbox\" name=\"mentioned_only\">\n"
39-            "<p><input type=\"file\" name=\"attach\">\n"
40+            "<p>%s: <input type=\"file\" name=\"attach\">\n"
41             "<p>%s: <input type=\"text\" name=\"alt_text\">\n"
42 
43             "<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n"
44@@ -648,6 +650,7 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, const char *md5)
45             id,
46             L("Sensitive content"),
47             L("Only for mentioned people"),
48+            L("Image"),
49             L("Image description"),
50             md5,
51             L("Post")
+25, -1
 1@@ -622,7 +622,31 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2 
 3                 st = xs_dict_append(st, "spoiler_text", tmp);
 4 
 5-                st = xs_dict_append(st, "media_attachments", el);
 6+                /* create the list of attachments */
 7+                xs *matt = xs_list_new();
 8+                xs_list *att = xs_dict_get(msg, "attachment");
 9+                xs_str *aobj;
10+
11+                while (xs_list_iter(&att, &aobj)) {
12+                    const char *mtype = xs_dict_get(aobj, "mediaType");
13+
14+                    if (!xs_is_null(mtype) && xs_startswith(mtype, "image/")) {
15+                        xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt));
16+                        xs *matte   = xs_dict_new();
17+
18+                        matte = xs_dict_append(matte, "id",          matteid);
19+                        matte = xs_dict_append(matte, "type",        "image");
20+                        matte = xs_dict_append(matte, "url",         xs_dict_get(aobj, "url"));
21+                        matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url"));
22+                        matte = xs_dict_append(matte, "remote_url",  xs_dict_get(aobj, "url"));
23+                        matte = xs_dict_append(matte, "description", xs_dict_get(aobj, "name"));
24+
25+                        matt = xs_list_append(matt, matte);
26+                    }
27+                }
28+
29+                st = xs_dict_append(st, "media_attachments", matt);
30+
31                 st = xs_dict_append(st, "mentions",          el);
32                 st = xs_dict_append(st, "tags",              el);
33                 st = xs_dict_append(st, "emojis",            el);