diff options
| author | 2023-01-28 18:22:42 +0100 | |
|---|---|---|
| committer | 2023-01-28 18:22:42 +0100 | |
| commit | 4e86847f7272b8d49d5210cfb954baa82cecf56b (patch) | |
| tree | 53130630e6aedaabe0e7c3dc9e9be9c44a6103d2 | |
| parent | New post field 'alt_text'. (diff) | |
| download | snac2-4e86847f7272b8d49d5210cfb954baa82cecf56b.tar.gz snac2-4e86847f7272b8d49d5210cfb954baa82cecf56b.tar.xz snac2-4e86847f7272b8d49d5210cfb954baa82cecf56b.zip | |
Image attachments in posts can now have descriptions ('alt text').
| -rw-r--r-- | activitypub.c | 25 | ||||
| -rw-r--r-- | html.c | 22 | ||||
| -rw-r--r-- | snac.h | 2 |
3 files changed, 31 insertions, 18 deletions
diff --git a/activitypub.c b/activitypub.c index 663ee3f..e52db31 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -620,7 +620,7 @@ d_char *msg_follow(snac *snac, char *url_or_uid) | |||
| 620 | } | 620 | } |
| 621 | 621 | ||
| 622 | 622 | ||
| 623 | d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char *attach) | 623 | xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts, xs_str *in_reply_to, xs_list *attach) |
| 624 | /* creates a 'Note' message */ | 624 | /* creates a 'Note' message */ |
| 625 | { | 625 | { |
| 626 | xs *ntid = tid(0); | 626 | xs *ntid = tid(0); |
| @@ -633,8 +633,9 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char | |||
| 633 | xs *irt = NULL; | 633 | xs *irt = NULL; |
| 634 | xs *tag = NULL; | 634 | xs *tag = NULL; |
| 635 | xs *atls = NULL; | 635 | xs *atls = NULL; |
| 636 | d_char *msg = msg_base(snac, "Note", id, NULL, "@now", NULL); | 636 | xs_dict *msg = msg_base(snac, "Note", id, NULL, "@now", NULL); |
| 637 | char *p, *v; | 637 | xs_list *p; |
| 638 | xs_val *v; | ||
| 638 | 639 | ||
| 639 | if (rcpts == NULL) | 640 | if (rcpts == NULL) |
| 640 | to = xs_list_new(); | 641 | to = xs_list_new(); |
| @@ -700,22 +701,18 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char | |||
| 700 | irt = xs_val_new(XSTYPE_NULL); | 701 | irt = xs_val_new(XSTYPE_NULL); |
| 701 | 702 | ||
| 702 | /* create the attachment list, if there are any */ | 703 | /* create the attachment list, if there are any */ |
| 703 | if (!xs_is_null(attach) && *attach != '\0') { | 704 | if (!xs_is_null(attach)) { |
| 704 | xs *lsof1 = NULL; | ||
| 705 | |||
| 706 | if (xs_type(attach) == XSTYPE_STRING) { | ||
| 707 | lsof1 = xs_list_append(xs_list_new(), attach); | ||
| 708 | attach = lsof1; | ||
| 709 | } | ||
| 710 | |||
| 711 | atls = xs_list_new(); | 705 | atls = xs_list_new(); |
| 706 | |||
| 712 | while (xs_list_iter(&attach, &v)) { | 707 | while (xs_list_iter(&attach, &v)) { |
| 713 | xs *d = xs_dict_new(); | 708 | xs *d = xs_dict_new(); |
| 714 | char *mime = xs_mime_by_ext(v); | 709 | char *url = xs_list_get(v, 0); |
| 710 | char *alt = xs_list_get(v, 1); | ||
| 711 | char *mime = xs_mime_by_ext(url); | ||
| 715 | 712 | ||
| 716 | d = xs_dict_append(d, "mediaType", mime); | 713 | d = xs_dict_append(d, "mediaType", mime); |
| 717 | d = xs_dict_append(d, "url", v); | 714 | d = xs_dict_append(d, "url", url); |
| 718 | d = xs_dict_append(d, "name", ""); | 715 | d = xs_dict_append(d, "name", alt); |
| 719 | d = xs_dict_append(d, "type", | 716 | d = xs_dict_append(d, "type", |
| 720 | xs_startswith(mime, "image/") ? "Image" : "Document"); | 717 | xs_startswith(mime, "image/") ? "Image" : "Document"); |
| 721 | 718 | ||
| @@ -1352,11 +1352,22 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, | |||
| 1352 | char *to = xs_dict_get(p_vars, "to"); | 1352 | char *to = xs_dict_get(p_vars, "to"); |
| 1353 | char *sensitive = xs_dict_get(p_vars, "sensitive"); | 1353 | char *sensitive = xs_dict_get(p_vars, "sensitive"); |
| 1354 | char *edit_id = xs_dict_get(p_vars, "edit_id"); | 1354 | char *edit_id = xs_dict_get(p_vars, "edit_id"); |
| 1355 | char *alt_text = xs_dict_get(p_vars, "alt_text"); | ||
| 1355 | xs *attach_list = xs_list_new(); | 1356 | xs *attach_list = xs_list_new(); |
| 1356 | 1357 | ||
| 1358 | /* default alt text */ | ||
| 1359 | if (xs_is_null(alt_text)) | ||
| 1360 | alt_text = ""; | ||
| 1361 | |||
| 1357 | /* is attach_url set? */ | 1362 | /* is attach_url set? */ |
| 1358 | if (!xs_is_null(attach_url) && *attach_url != '\0') | 1363 | if (!xs_is_null(attach_url) && *attach_url != '\0') { |
| 1359 | attach_list = xs_list_append(attach_list, attach_url); | 1364 | xs *l = xs_list_new(); |
| 1365 | |||
| 1366 | l = xs_list_append(l, attach_url); | ||
| 1367 | l = xs_list_append(l, alt_text); | ||
| 1368 | |||
| 1369 | attach_list = xs_list_append(attach_list, l); | ||
| 1370 | } | ||
| 1360 | 1371 | ||
| 1361 | /* is attach_file set? */ | 1372 | /* is attach_file set? */ |
| 1362 | if (!xs_is_null(attach_file) && xs_type(attach_file) == XSTYPE_LIST) { | 1373 | 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, | |||
| 1373 | /* store */ | 1384 | /* store */ |
| 1374 | static_put(&snac, id, payload + fo, fs); | 1385 | static_put(&snac, id, payload + fo, fs); |
| 1375 | 1386 | ||
| 1376 | attach_list = xs_list_append(attach_list, url); | 1387 | xs *l = xs_list_new(); |
| 1388 | |||
| 1389 | l = xs_list_append(l, url); | ||
| 1390 | l = xs_list_append(l, alt_text); | ||
| 1391 | |||
| 1392 | attach_list = xs_list_append(attach_list, l); | ||
| 1377 | } | 1393 | } |
| 1378 | } | 1394 | } |
| 1379 | 1395 | ||
| @@ -151,7 +151,7 @@ const char *default_avatar_base64(void); | |||
| 151 | d_char *msg_admiration(snac *snac, char *object, char *type); | 151 | d_char *msg_admiration(snac *snac, char *object, char *type); |
| 152 | d_char *msg_create(snac *snac, char *object); | 152 | d_char *msg_create(snac *snac, char *object); |
| 153 | d_char *msg_follow(snac *snac, char *actor); | 153 | d_char *msg_follow(snac *snac, char *actor); |
| 154 | d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char *attach); | 154 | xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts, xs_str *in_reply_to, xs_list *attach); |
| 155 | d_char *msg_undo(snac *snac, char *object); | 155 | d_char *msg_undo(snac *snac, char *object); |
| 156 | d_char *msg_delete(snac *snac, char *id); | 156 | d_char *msg_delete(snac *snac, char *id); |
| 157 | d_char *msg_actor(snac *snac); | 157 | d_char *msg_actor(snac *snac); |