From 78ec3b077b989bcae5950d75f4ee0cb03bd10030 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 10 Oct 2022 09:03:07 +0200 Subject: Media can be attached to notes. The web interface limits this (by now) to only one attachment, given the URL. --- activitypub.c | 30 +++++++++++++++++++++++++++++- html.c | 17 +++++++++++++---- main.c | 2 +- snac.h | 2 +- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/activitypub.c b/activitypub.c index 8771ee8..fb790d5 100644 --- a/activitypub.c +++ b/activitypub.c @@ -508,7 +508,7 @@ d_char *msg_follow(snac *snac, char *actor) } -d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to) +d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char *attach) /* creates a 'Note' message */ { xs *ntid = tid(0); @@ -520,6 +520,7 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to) xs *cc = xs_list_new(); xs *irt = NULL; xs *tag = NULL; + xs *atls = NULL; d_char *msg = msg_base(snac, "Note", id, NULL, "@now", NULL); char *p, *v; @@ -561,6 +562,30 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to) else irt = xs_val_new(XSTYPE_NULL); + /* create the attachment list, if there are any */ + if (!xs_is_null(attach) && *attach != '\0') { + xs *lsof1 = NULL; + + if (xs_type(attach) == XSTYPE_STRING) { + lsof1 = xs_list_append(xs_list_new(), attach); + attach = lsof1; + } + + atls = xs_list_new(); + while (xs_list_iter(&attach, &v)) { + xs *d = xs_dict_new(); + char *mime = xs_mime_by_ext(v); + + d = xs_dict_append(d, "mediaType", mime); + d = xs_dict_append(d, "url", v); + d = xs_dict_append(d, "name", ""); + d = xs_dict_append(d, "type", + xs_startswith(mime, "image/") ? "Image" : "Document"); + + atls = xs_list_append(atls, d); + } + } + if (tag == NULL) tag = xs_list_new(); @@ -594,6 +619,9 @@ d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to) msg = xs_dict_append(msg, "inReplyTo", irt); msg = xs_dict_append(msg, "tag", tag); + if (atls != NULL) + msg = xs_dict_append(msg, "attachment", atls); + return msg; } diff --git a/html.c b/html.c index 167d685..a6b6f0e 100644 --- a/html.c +++ b/html.c @@ -195,6 +195,7 @@ d_char *html_top_controls(snac *snac, d_char *s) "rows=\"8\" wrap=\"virtual\" required=\"required\">\n" "\n" "\n" + " Image URL
" "
\n" "\n" @@ -204,12 +205,12 @@ d_char *html_top_controls(snac *snac, d_char *s) "
\n" + "\n" "
\n" + "\n"
"%s
\n"
@@ -222,7 +223,7 @@ d_char *html_top_controls(snac *snac, d_char *s)
"
%s:
\n"
- "
%s:
\n"
"