commit 4e86847
default
·
2023-01-28 17:22:42 +0000 UTC
parent d3cf86c
Image attachments in posts can now have descriptions ('alt text').
3 files changed,
+31,
-18
+11,
-14
1@@ -620,7 +620,7 @@ d_char *msg_follow(snac *snac, char *url_or_uid)
2 }
3
4
5-d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char *attach)
6+xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts, xs_str *in_reply_to, xs_list *attach)
7 /* creates a 'Note' message */
8 {
9 xs *ntid = tid(0);
10@@ -633,8 +633,9 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char
11 xs *irt = NULL;
12 xs *tag = NULL;
13 xs *atls = NULL;
14- d_char *msg = msg_base(snac, "Note", id, NULL, "@now", NULL);
15- char *p, *v;
16+ xs_dict *msg = msg_base(snac, "Note", id, NULL, "@now", NULL);
17+ xs_list *p;
18+ xs_val *v;
19
20 if (rcpts == NULL)
21 to = xs_list_new();
22@@ -700,22 +701,18 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char
23 irt = xs_val_new(XSTYPE_NULL);
24
25 /* create the attachment list, if there are any */
26- if (!xs_is_null(attach) && *attach != '\0') {
27- xs *lsof1 = NULL;
28-
29- if (xs_type(attach) == XSTYPE_STRING) {
30- lsof1 = xs_list_append(xs_list_new(), attach);
31- attach = lsof1;
32- }
33-
34+ if (!xs_is_null(attach)) {
35 atls = xs_list_new();
36+
37 while (xs_list_iter(&attach, &v)) {
38 xs *d = xs_dict_new();
39- char *mime = xs_mime_by_ext(v);
40+ char *url = xs_list_get(v, 0);
41+ char *alt = xs_list_get(v, 1);
42+ char *mime = xs_mime_by_ext(url);
43
44 d = xs_dict_append(d, "mediaType", mime);
45- d = xs_dict_append(d, "url", v);
46- d = xs_dict_append(d, "name", "");
47+ d = xs_dict_append(d, "url", url);
48+ d = xs_dict_append(d, "name", alt);
49 d = xs_dict_append(d, "type",
50 xs_startswith(mime, "image/") ? "Image" : "Document");
51
M
html.c
+19,
-3
1@@ -1352,11 +1352,22 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
2 char *to = xs_dict_get(p_vars, "to");
3 char *sensitive = xs_dict_get(p_vars, "sensitive");
4 char *edit_id = xs_dict_get(p_vars, "edit_id");
5+ char *alt_text = xs_dict_get(p_vars, "alt_text");
6 xs *attach_list = xs_list_new();
7
8+ /* default alt text */
9+ if (xs_is_null(alt_text))
10+ alt_text = "";
11+
12 /* is attach_url set? */
13- if (!xs_is_null(attach_url) && *attach_url != '\0')
14- attach_list = xs_list_append(attach_list, attach_url);
15+ if (!xs_is_null(attach_url) && *attach_url != '\0') {
16+ xs *l = xs_list_new();
17+
18+ l = xs_list_append(l, attach_url);
19+ l = xs_list_append(l, alt_text);
20+
21+ attach_list = xs_list_append(attach_list, l);
22+ }
23
24 /* is attach_file set? */
25 if (!xs_is_null(attach_file) && xs_type(attach_file) == XSTYPE_LIST) {
26@@ -1373,7 +1384,12 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
27 /* store */
28 static_put(&snac, id, payload + fo, fs);
29
30- attach_list = xs_list_append(attach_list, url);
31+ xs *l = xs_list_new();
32+
33+ l = xs_list_append(l, url);
34+ l = xs_list_append(l, alt_text);
35+
36+ attach_list = xs_list_append(attach_list, l);
37 }
38 }
39
M
snac.h
+1,
-1
1@@ -151,7 +151,7 @@ const char *default_avatar_base64(void);
2 d_char *msg_admiration(snac *snac, char *object, char *type);
3 d_char *msg_create(snac *snac, char *object);
4 d_char *msg_follow(snac *snac, char *actor);
5-d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char *attach);
6+xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts, xs_str *in_reply_to, xs_list *attach);
7 d_char *msg_undo(snac *snac, char *object);
8 d_char *msg_delete(snac *snac, char *id);
9 d_char *msg_actor(snac *snac);