diff options
| -rw-r--r-- | html.c | 72 |
1 files changed, 69 insertions, 3 deletions
| @@ -479,6 +479,39 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, const char *md5) | |||
| 479 | 479 | ||
| 480 | s = xs_str_cat(s, "</form>\n"); | 480 | s = xs_str_cat(s, "</form>\n"); |
| 481 | 481 | ||
| 482 | char *prev_src = xs_dict_get(msg, "sourceContent"); | ||
| 483 | |||
| 484 | if (!xs_is_null(prev_src) && strcmp(actor, snac->actor) == 0) { | ||
| 485 | /* post can be edited */ | ||
| 486 | xs *s1 = xs_fmt( | ||
| 487 | "<p><details><summary>%s</summary>\n" | ||
| 488 | "<p><div class=\"snac-note\" id=\"%s_edit\">\n" | ||
| 489 | "<form method=\"post\" action=\"%s/admin/note\" " | ||
| 490 | "enctype=\"multipart/form-data\" id=\"%s_edit_form\">\n" | ||
| 491 | "<textarea class=\"snac-textarea\" name=\"content\" " | ||
| 492 | "rows=\"4\" wrap=\"virtual\" required=\"required\">%s</textarea>\n" | ||
| 493 | "<input type=\"hidden\" name=\"edit_id\" value=\"%s\">\n" | ||
| 494 | "<p><input type=\"checkbox\" name=\"sensitive\"> %s\n" | ||
| 495 | "<p><input type=\"file\" name=\"attach\">\n" | ||
| 496 | "<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n" | ||
| 497 | "<p><input type=\"submit\" class=\"button\" value=\"%s\">\n" | ||
| 498 | "</form><p></div>\n" | ||
| 499 | "</details><p>" | ||
| 500 | "\n", | ||
| 501 | |||
| 502 | L("Edit..."), | ||
| 503 | md5, | ||
| 504 | snac->actor, md5, | ||
| 505 | prev_src, | ||
| 506 | id, | ||
| 507 | L("Sensitive content"), | ||
| 508 | md5, | ||
| 509 | L("Post") | ||
| 510 | ); | ||
| 511 | |||
| 512 | s = xs_str_cat(s, s1); | ||
| 513 | } | ||
| 514 | |||
| 482 | { | 515 | { |
| 483 | /* the post textarea */ | 516 | /* the post textarea */ |
| 484 | xs *ct = build_mentions(snac, msg); | 517 | xs *ct = build_mentions(snac, msg); |
| @@ -1309,6 +1342,7 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, | |||
| 1309 | char *attach_file = xs_dict_get(p_vars, "attach"); | 1342 | char *attach_file = xs_dict_get(p_vars, "attach"); |
| 1310 | char *to = xs_dict_get(p_vars, "to"); | 1343 | char *to = xs_dict_get(p_vars, "to"); |
| 1311 | char *sensitive = xs_dict_get(p_vars, "sensitive"); | 1344 | char *sensitive = xs_dict_get(p_vars, "sensitive"); |
| 1345 | char *edit_id = xs_dict_get(p_vars, "edit_id"); | ||
| 1312 | xs *attach_list = xs_list_new(); | 1346 | xs *attach_list = xs_list_new(); |
| 1313 | 1347 | ||
| 1314 | /* is attach_url set? */ | 1348 | /* is attach_url set? */ |
| @@ -1348,11 +1382,43 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, | |||
| 1348 | msg = xs_dict_set(msg, "summary", "..."); | 1382 | msg = xs_dict_set(msg, "summary", "..."); |
| 1349 | } | 1383 | } |
| 1350 | 1384 | ||
| 1351 | c_msg = msg_create(&snac, msg); | 1385 | if (xs_is_null(edit_id)) { |
| 1386 | /* new message */ | ||
| 1387 | c_msg = msg_create(&snac, msg); | ||
| 1388 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | ||
| 1389 | } | ||
| 1390 | else { | ||
| 1391 | /* an edition of a previous message */ | ||
| 1392 | xs *p_msg = NULL; | ||
| 1393 | |||
| 1394 | if (valid_status(object_get(edit_id, &p_msg, NULL))) { | ||
| 1395 | /* copy relevant fields from previous version */ | ||
| 1396 | char *fields[] = { "id", "context", "url", "published", | ||
| 1397 | "to", "inReplyTo", NULL }; | ||
| 1398 | int n; | ||
| 1399 | |||
| 1400 | for (n = 0; fields[n]; n++) { | ||
| 1401 | char *v = xs_dict_get(p_msg, fields[n]); | ||
| 1402 | msg = xs_dict_set(msg, fields[n], v); | ||
| 1403 | } | ||
| 1404 | |||
| 1405 | /* set the updated field */ | ||
| 1406 | xs *updated = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ"); | ||
| 1407 | msg = xs_dict_set(msg, "updated", updated); | ||
| 1408 | |||
| 1409 | /* overwrite object, not updating the indexes */ | ||
| 1410 | object_add_ow(edit_id, msg); | ||
| 1411 | |||
| 1412 | /* update message */ | ||
| 1413 | c_msg = msg_update(&snac, msg); | ||
| 1414 | } | ||
| 1415 | else | ||
| 1416 | snac_log(&snac, xs_fmt("cannot get object '%s' for editing", edit_id)); | ||
| 1417 | } | ||
| 1352 | 1418 | ||
| 1353 | enqueue_message(&snac, c_msg); | 1419 | if (c_msg != NULL) |
| 1420 | enqueue_message(&snac, c_msg); | ||
| 1354 | 1421 | ||
| 1355 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | ||
| 1356 | } | 1422 | } |
| 1357 | 1423 | ||
| 1358 | status = 303; | 1424 | status = 303; |