diff options
author | default <nobody@localhost> | 2022-10-10 09:03:07 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2022-10-10 09:03:15 +0200 |
commit | 78ec3b077b989bcae5950d75f4ee0cb03bd10030 (patch) | |
tree | 6f3556e88b3dd3a1dd90b044862b631e3d6da1c9 /activitypub.c | |
parent | 106835b11e9fa54af91aec5d8b9cafa37559b14a (diff) |
Media can be attached to notes.
The web interface limits this (by now) to only one
attachment, given the URL.
Diffstat (limited to 'activitypub.c')
-rw-r--r-- | activitypub.c | 30 |
1 files changed, 29 insertions, 1 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; } |