Media can be attached to notes.

The web interface limits this (by now) to only one
attachment, given the URL.
This commit is contained in:
default 2022-10-10 09:03:07 +02:00
parent 106835b11e
commit 78ec3b077b
4 changed files with 44 additions and 7 deletions

View File

@ -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;
}

17
html.c
View File

@ -195,6 +195,7 @@ d_char *html_top_controls(snac *snac, d_char *s)
"rows=\"8\" wrap=\"virtual\" required=\"required\"></textarea>\n"
"<input type=\"hidden\" name=\"in_reply_to\" value=\"\">\n"
"<input type=\"submit\" class=\"button\" value=\"%s\">\n"
"<input type=\"text\" name=\"attach_url\"> Image URL<p>"
"</form><p>\n"
"</div>\n"
@ -204,12 +205,12 @@ d_char *html_top_controls(snac *snac, d_char *s)
"<form method=\"post\" action=\"%s/admin/action\">\n"
"<input type=\"text\" name=\"actor\" required=\"required\">\n"
"<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n"
"</form></p>\n"
"</form><p>\n"
"<form method=\"post\" action=\"%s/admin/action\">\n"
"<input type=\"text\" name=\"id\" required=\"required\">\n"
"<input type=\"submit\" name=\"action\" value=\"%s\"> %s\n"
"</form></p>\n"
"</form><p>\n"
"<details><summary>%s</summary>\n"
@ -222,7 +223,7 @@ d_char *html_top_controls(snac *snac, d_char *s)
"<input type=\"text\" name=\"avatar\" value=\"%s\"></p>\n"
"<p>%s:<br>\n"
"<textarea name=\"bio\" cols=60 rows=4>%s</textarea></p>\n"
"<textarea name=\"bio\" cols=\"40\" rows=\"4\">%s</textarea></p>\n"
"<p>%s:<br>\n"
"<input type=\"password\" name=\"passwd1\" value=\"\"></p>\n"
@ -854,16 +855,24 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
p_vars = xs_dict_get(req, "p_vars");
#if 0
{
xs *j1 = xs_json_dumps_pp(p_vars, 4);
printf("%s\n", j1);
}
#endif
if (p_path && strcmp(p_path, "admin/note") == 0) {
/* post note */
char *content = xs_dict_get(p_vars, "content");
char *in_reply_to = xs_dict_get(p_vars, "in_reply_to");
char *attach_url = xs_dict_get(p_vars, "attach_url");
if (content != NULL) {
xs *msg = NULL;
xs *c_msg = NULL;
msg = msg_note(&snac, content, NULL, in_reply_to);
msg = msg_note(&snac, content, NULL, in_reply_to, attach_url);
c_msg = msg_create(&snac, msg);

2
main.c
View File

@ -235,7 +235,7 @@ int main(int argc, char *argv[])
else
content = xs_dup(url);
msg = msg_note(&snac, content, NULL, in_reply_to);
msg = msg_note(&snac, content, NULL, in_reply_to, NULL);
c_msg = msg_create(&snac, msg);

2
snac.h
View File

@ -111,7 +111,7 @@ int webfinger_get_handler(d_char *req, char *q_path,
d_char *msg_admiration(snac *snac, char *object, char *type);
d_char *msg_create(snac *snac, char *object);
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);
d_char *msg_undo(snac *snac, char *object);
d_char *msg_delete(snac *snac, char *id);
d_char *msg_actor(snac *snac);