Image attachments in posts can now have descriptions ('alt text').

This commit is contained in:
default 2023-01-28 18:22:42 +01:00
parent d3cf86c098
commit 4e86847f72
3 changed files with 31 additions and 18 deletions

View file

@ -620,7 +620,7 @@ d_char *msg_follow(snac *snac, char *url_or_uid)
} }
d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char *attach) xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts, xs_str *in_reply_to, xs_list *attach)
/* creates a 'Note' message */ /* creates a 'Note' message */
{ {
xs *ntid = tid(0); xs *ntid = tid(0);
@ -633,8 +633,9 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char
xs *irt = NULL; xs *irt = NULL;
xs *tag = NULL; xs *tag = NULL;
xs *atls = NULL; xs *atls = NULL;
d_char *msg = msg_base(snac, "Note", id, NULL, "@now", NULL); xs_dict *msg = msg_base(snac, "Note", id, NULL, "@now", NULL);
char *p, *v; xs_list *p;
xs_val *v;
if (rcpts == NULL) if (rcpts == NULL)
to = xs_list_new(); to = xs_list_new();
@ -700,22 +701,18 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char
irt = xs_val_new(XSTYPE_NULL); irt = xs_val_new(XSTYPE_NULL);
/* create the attachment list, if there are any */ /* create the attachment list, if there are any */
if (!xs_is_null(attach) && *attach != '\0') { if (!xs_is_null(attach)) {
xs *lsof1 = NULL;
if (xs_type(attach) == XSTYPE_STRING) {
lsof1 = xs_list_append(xs_list_new(), attach);
attach = lsof1;
}
atls = xs_list_new(); atls = xs_list_new();
while (xs_list_iter(&attach, &v)) { while (xs_list_iter(&attach, &v)) {
xs *d = xs_dict_new(); xs *d = xs_dict_new();
char *mime = xs_mime_by_ext(v); char *url = xs_list_get(v, 0);
char *alt = xs_list_get(v, 1);
char *mime = xs_mime_by_ext(url);
d = xs_dict_append(d, "mediaType", mime); d = xs_dict_append(d, "mediaType", mime);
d = xs_dict_append(d, "url", v); d = xs_dict_append(d, "url", url);
d = xs_dict_append(d, "name", ""); d = xs_dict_append(d, "name", alt);
d = xs_dict_append(d, "type", d = xs_dict_append(d, "type",
xs_startswith(mime, "image/") ? "Image" : "Document"); xs_startswith(mime, "image/") ? "Image" : "Document");

22
html.c
View file

@ -1352,11 +1352,22 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
char *to = xs_dict_get(p_vars, "to"); char *to = xs_dict_get(p_vars, "to");
char *sensitive = xs_dict_get(p_vars, "sensitive"); char *sensitive = xs_dict_get(p_vars, "sensitive");
char *edit_id = xs_dict_get(p_vars, "edit_id"); char *edit_id = xs_dict_get(p_vars, "edit_id");
char *alt_text = xs_dict_get(p_vars, "alt_text");
xs *attach_list = xs_list_new(); xs *attach_list = xs_list_new();
/* default alt text */
if (xs_is_null(alt_text))
alt_text = "";
/* is attach_url set? */ /* is attach_url set? */
if (!xs_is_null(attach_url) && *attach_url != '\0') if (!xs_is_null(attach_url) && *attach_url != '\0') {
attach_list = xs_list_append(attach_list, attach_url); xs *l = xs_list_new();
l = xs_list_append(l, attach_url);
l = xs_list_append(l, alt_text);
attach_list = xs_list_append(attach_list, l);
}
/* is attach_file set? */ /* is attach_file set? */
if (!xs_is_null(attach_file) && xs_type(attach_file) == XSTYPE_LIST) { if (!xs_is_null(attach_file) && xs_type(attach_file) == XSTYPE_LIST) {
@ -1373,7 +1384,12 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
/* store */ /* store */
static_put(&snac, id, payload + fo, fs); static_put(&snac, id, payload + fo, fs);
attach_list = xs_list_append(attach_list, url); xs *l = xs_list_new();
l = xs_list_append(l, url);
l = xs_list_append(l, alt_text);
attach_list = xs_list_append(attach_list, l);
} }
} }

2
snac.h
View file

@ -151,7 +151,7 @@ const char *default_avatar_base64(void);
d_char *msg_admiration(snac *snac, char *object, char *type); d_char *msg_admiration(snac *snac, char *object, char *type);
d_char *msg_create(snac *snac, char *object); d_char *msg_create(snac *snac, char *object);
d_char *msg_follow(snac *snac, char *actor); d_char *msg_follow(snac *snac, char *actor);
d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char *attach); xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts, xs_str *in_reply_to, xs_list *attach);
d_char *msg_undo(snac *snac, char *object); d_char *msg_undo(snac *snac, char *object);
d_char *msg_delete(snac *snac, char *id); d_char *msg_delete(snac *snac, char *id);
d_char *msg_actor(snac *snac); d_char *msg_actor(snac *snac);