summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-04-10 13:22:59 +0200
committerdefault <nobody@localhost>2023-04-10 13:22:59 +0200
commit9e9d740199e11ca79463f9f4df6f55f0e25cc1aa (patch)
treedcc77be55ee993938c58923960ddc07dcb618593
parent3fb651b7b124dbe398e4099a233074a145ea482d (diff)
Added image attachments.
-rw-r--r--html.c9
-rw-r--r--mastoapi.c26
2 files changed, 31 insertions, 4 deletions
diff --git a/html.c b/html.c
index 9850dfd..c8d3e39 100644
--- a/html.c
+++ b/html.c
@@ -332,7 +332,7 @@ d_char *html_top_controls(snac *snac, d_char *s)
"<input type=\"hidden\" name=\"in_reply_to\" value=\"\">\n"
"<p>%s: <input type=\"checkbox\" name=\"sensitive\">\n"
"<p>%s: <input type=\"checkbox\" name=\"mentioned_only\">\n"
- "<p><input type=\"file\" name=\"attach\">\n"
+ "<p>%s: <input type=\"file\" name=\"attach\">\n"
"<p>%s: <input type=\"text\" name=\"alt_text\">\n"
"<p><input type=\"submit\" class=\"button\" value=\"%s\">\n"
"</form><p>\n"
@@ -425,6 +425,7 @@ d_char *html_top_controls(snac *snac, d_char *s)
snac->actor,
L("Sensitive content"),
L("Only for mentioned people"),
+ L("Image"),
L("Image description"),
L("Post"),
@@ -593,7 +594,7 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, const char *md5)
"<p>%s: <input type=\"checkbox\" name=\"sensitive\">\n"
"<p>%s: <input type=\"checkbox\" name=\"mentioned_only\">\n"
- "<p><input type=\"file\" name=\"attach\">\n"
+ "<p>%s: <input type=\"file\" name=\"attach\">\n"
"<p>%s: <input type=\"text\" name=\"alt_text\">\n"
"<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n"
@@ -609,6 +610,7 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, const char *md5)
id,
L("Sensitive content"),
L("Only for mentioned people"),
+ L("Image"),
L("Image description"),
md5,
L("Post")
@@ -632,7 +634,7 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, const char *md5)
"<p>%s: <input type=\"checkbox\" name=\"sensitive\">\n"
"<p>%s: <input type=\"checkbox\" name=\"mentioned_only\">\n"
- "<p><input type=\"file\" name=\"attach\">\n"
+ "<p>%s: <input type=\"file\" name=\"attach\">\n"
"<p>%s: <input type=\"text\" name=\"alt_text\">\n"
"<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n"
@@ -648,6 +650,7 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, const char *md5)
id,
L("Sensitive content"),
L("Only for mentioned people"),
+ L("Image"),
L("Image description"),
md5,
L("Post")
diff --git a/mastoapi.c b/mastoapi.c
index bbdcff9..b223ce4 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -622,7 +622,31 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
st = xs_dict_append(st, "spoiler_text", tmp);
- st = xs_dict_append(st, "media_attachments", el);
+ /* create the list of attachments */
+ xs *matt = xs_list_new();
+ xs_list *att = xs_dict_get(msg, "attachment");
+ xs_str *aobj;
+
+ while (xs_list_iter(&att, &aobj)) {
+ const char *mtype = xs_dict_get(aobj, "mediaType");
+
+ if (!xs_is_null(mtype) && xs_startswith(mtype, "image/")) {
+ xs *matteid = xs_fmt("%s_%d", id, xs_list_len(matt));
+ xs *matte = xs_dict_new();
+
+ matte = xs_dict_append(matte, "id", matteid);
+ matte = xs_dict_append(matte, "type", "image");
+ matte = xs_dict_append(matte, "url", xs_dict_get(aobj, "url"));
+ matte = xs_dict_append(matte, "preview_url", xs_dict_get(aobj, "url"));
+ matte = xs_dict_append(matte, "remote_url", xs_dict_get(aobj, "url"));
+ matte = xs_dict_append(matte, "description", xs_dict_get(aobj, "name"));
+
+ matt = xs_list_append(matt, matte);
+ }
+ }
+
+ st = xs_dict_append(st, "media_attachments", matt);
+
st = xs_dict_append(st, "mentions", el);
st = xs_dict_append(st, "tags", el);
st = xs_dict_append(st, "emojis", el);