summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to 'html.c')
-rw-r--r--html.c111
1 files changed, 67 insertions, 44 deletions
diff --git a/html.c b/html.c
index 115e8c4..d4cbb35 100644
--- a/html.c
+++ b/html.c
@@ -350,7 +350,7 @@ xs_html *html_note(snac *user, const char *summary,
350 const xs_val *mnt_only, const char *redir, 350 const xs_val *mnt_only, const char *redir,
351 const char *in_reply_to, int poll, 351 const char *in_reply_to, int poll,
352 const xs_list *att_files, const xs_list *att_alt_texts, 352 const xs_list *att_files, const xs_list *att_alt_texts,
353 int is_draft) 353 int is_draft, const char *published)
354/* Yes, this is a FUCKTON of arguments and I'm a bit embarrased */ 354/* Yes, this is a FUCKTON of arguments and I'm a bit embarrased */
355{ 355{
356 xs *action = xs_fmt("%s/admin/note", user->actor); 356 xs *action = xs_fmt("%s/admin/note", user->actor);
@@ -440,6 +440,34 @@ xs_html *html_note(snac *user, const char *summary,
440 xs_html_attr("name", "is_draft"), 440 xs_html_attr("name", "is_draft"),
441 xs_html_attr(is_draft ? "checked" : "", NULL)))); 441 xs_html_attr(is_draft ? "checked" : "", NULL))));
442 442
443 /* post date and time */
444 xs *post_date = NULL;
445 xs *post_time = NULL;
446
447 if (xs_is_string(published)) {
448 time_t t = xs_parse_iso_date(published, 0);
449
450 if (t > 0) {
451 post_date = xs_str_time(t, "%Y-%m-%d", 1);
452 post_time = xs_str_time(t, "%H:%M:%S", 1);
453 }
454 }
455
456 xs_html_add(form,
457 xs_html_tag("p",
458 xs_html_text(L("Post date and time (empty, right now; in the future, schedule for later):")),
459 xs_html_sctag("br", NULL),
460 xs_html_sctag("input",
461 xs_html_attr("type", "date"),
462 xs_html_attr("value", post_date ? post_date : ""),
463 xs_html_attr("name", "post_date")),
464 xs_html_text(" "),
465 xs_html_sctag("input",
466 xs_html_attr("type", "time"),
467 xs_html_attr("value", post_time ? post_time : ""),
468 xs_html_attr("step", "1"),
469 xs_html_attr("name", "post_time"))));
470
443 if (edit_id) 471 if (edit_id)
444 xs_html_add(form, 472 xs_html_add(form,
445 xs_html_sctag("input", 473 xs_html_sctag("input",
@@ -559,30 +587,6 @@ xs_html *html_note(snac *user, const char *summary,
559 xs_html_text(L("End in 1 day")))))); 587 xs_html_text(L("End in 1 day"))))));
560 } 588 }
561 589
562#if 0
563 /* scheduled post data */
564 xs *sched_date = xs_dup("");
565 xs *sched_time = xs_dup("");
566
567 xs_html_add(form,
568 xs_html_tag("p", NULL),
569 xs_html_tag("details",
570 xs_html_tag("summary",
571 xs_html_text(L("Scheduled post..."))),
572 xs_html_tag("p",
573 xs_html_text(L("Post date: ")),
574 xs_html_sctag("input",
575 xs_html_attr("type", "date"),
576 xs_html_attr("value", sched_date),
577 xs_html_attr("name", "post_date")),
578 xs_html_text(" "),
579 xs_html_text(L("Post time: ")),
580 xs_html_sctag("input",
581 xs_html_attr("type", "time"),
582 xs_html_attr("value", sched_time),
583 xs_html_attr("name", "post_time")))));
584#endif
585
586 xs_html_add(form, 590 xs_html_add(form,
587 xs_html_tag("p", NULL), 591 xs_html_tag("p", NULL),
588 xs_html_sctag("input", 592 xs_html_sctag("input",
@@ -1151,7 +1155,7 @@ xs_html *html_top_controls(snac *user)
1151 NULL, NULL, 1155 NULL, NULL,
1152 xs_stock(XSTYPE_FALSE), "", 1156 xs_stock(XSTYPE_FALSE), "",
1153 xs_stock(XSTYPE_FALSE), NULL, 1157 xs_stock(XSTYPE_FALSE), NULL,
1154 NULL, 1, NULL, NULL, 0), 1158 NULL, 1, NULL, NULL, 0, NULL),
1155 1159
1156 /** operations **/ 1160 /** operations **/
1157 xs_html_tag("details", 1161 xs_html_tag("details",
@@ -1809,7 +1813,8 @@ xs_html *html_entry_controls(snac *user, const char *actor,
1809 id, NULL, 1813 id, NULL,
1810 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"), 1814 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
1811 xs_stock(is_msg_public(msg) ? XSTYPE_FALSE : XSTYPE_TRUE), redir, 1815 xs_stock(is_msg_public(msg) ? XSTYPE_FALSE : XSTYPE_TRUE), redir,
1812 NULL, 0, att_files, att_alt_texts, is_draft(user, id))), 1816 NULL, 0, att_files, att_alt_texts, is_draft(user, id),
1817 xs_dict_get(msg, "published"))),
1813 xs_html_tag("p", NULL)); 1818 xs_html_tag("p", NULL));
1814 } 1819 }
1815 1820
@@ -1828,7 +1833,7 @@ xs_html *html_entry_controls(snac *user, const char *actor,
1828 NULL, NULL, 1833 NULL, NULL,
1829 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"), 1834 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
1830 xs_stock(is_msg_public(msg) ? XSTYPE_FALSE : XSTYPE_TRUE), redir, 1835 xs_stock(is_msg_public(msg) ? XSTYPE_FALSE : XSTYPE_TRUE), redir,
1831 id, 0, NULL, NULL, 0)), 1836 id, 0, NULL, NULL, 0, NULL)),
1832 xs_html_tag("p", NULL)); 1837 xs_html_tag("p", NULL));
1833 } 1838 }
1834 1839
@@ -3165,7 +3170,7 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c
3165 NULL, actor_id, 3170 NULL, actor_id,
3166 xs_stock(XSTYPE_FALSE), "", 3171 xs_stock(XSTYPE_FALSE), "",
3167 xs_stock(XSTYPE_FALSE), NULL, 3172 xs_stock(XSTYPE_FALSE), NULL,
3168 NULL, 0, NULL, NULL, 0), 3173 NULL, 0, NULL, NULL, 0, NULL),
3169 xs_html_tag("p", NULL)); 3174 xs_html_tag("p", NULL));
3170 3175
3171 xs_html_add(snac_post, snac_controls); 3176 xs_html_add(snac_post, snac_controls);
@@ -4305,23 +4310,29 @@ int html_post_handler(const xs_dict *req, const char *q_path,
4305 msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary); 4310 msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary);
4306 } 4311 }
4307 4312
4308 if (*post_date) { 4313 if (xs_is_string(post_date) && *post_date) {
4309 /* scheduled post */ 4314 xs *local_pubdate = xs_fmt("%sT%s", post_date,
4310 xs *sched_date = xs_fmt("%sT%s:00", post_date, *post_time ? post_time : "12:00"); 4315 xs_is_string(post_time) && *post_time ? post_time : "00:00:00");
4311 time_t t = xs_parse_localtime(sched_date, "%Y-%m-%dT%H:%M:%S"); 4316
4317 time_t t = xs_parse_iso_date(local_pubdate, 1);
4312 4318
4313 if (t != 0) { 4319 if (t != 0) {
4314 xs *iso_date = xs_str_iso_date(t); 4320 xs *iso_date = xs_str_iso_date(t);
4315 msg = xs_dict_set(msg, "published", iso_date); 4321 msg = xs_dict_set(msg, "published", iso_date);
4316 4322
4317 snac_debug(&snac, 1, xs_fmt("Scheduled date: [%s]", iso_date)); 4323 snac_debug(&snac, 1, xs_fmt("Published date: [%s]", iso_date));
4318 }
4319 else {
4320 snac_log(&snac, xs_fmt("Invalid scheduled date: [%s]", sched_date));
4321 post_date = "";
4322 } 4324 }
4325 else
4326 snac_log(&snac, xs_fmt("Invalid post date: [%s]", local_pubdate));
4323 } 4327 }
4324 4328
4329 /* is the published date from the future? */
4330 int future_post = 0;
4331 xs *right_now = xs_str_utctime(0, ISO_DATE_SPEC);
4332
4333 if (strcmp(xs_dict_get(msg, "published"), right_now) > 0)
4334 future_post = 1;
4335
4325 if (xs_is_null(edit_id)) { 4336 if (xs_is_null(edit_id)) {
4326 /* new message */ 4337 /* new message */
4327 const char *id = xs_dict_get(msg, "id"); 4338 const char *id = xs_dict_get(msg, "id");
@@ -4329,6 +4340,10 @@ int html_post_handler(const xs_dict *req, const char *q_path,
4329 if (store_as_draft) { 4340 if (store_as_draft) {
4330 draft_add(&snac, id, msg); 4341 draft_add(&snac, id, msg);
4331 } 4342 }
4343 else
4344 if (future_post) {
4345 snac_log(&snac, xs_fmt("DUMMY scheduled post 1 %s", id));
4346 }
4332 else { 4347 else {
4333 c_msg = msg_create(&snac, msg); 4348 c_msg = msg_create(&snac, msg);
4334 timeline_add(&snac, id, msg); 4349 timeline_add(&snac, id, msg);
@@ -4340,7 +4355,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
4340 4355
4341 if (valid_status(object_get(edit_id, &p_msg))) { 4356 if (valid_status(object_get(edit_id, &p_msg))) {
4342 /* copy relevant fields from previous version */ 4357 /* copy relevant fields from previous version */
4343 char *fields[] = { "id", "context", "url", "published", 4358 char *fields[] = { "id", "context", "url",
4344 "to", "inReplyTo", NULL }; 4359 "to", "inReplyTo", NULL };
4345 int n; 4360 int n;
4346 4361
@@ -4356,15 +4371,23 @@ int html_post_handler(const xs_dict *req, const char *q_path,
4356 if (is_draft(&snac, edit_id)) { 4371 if (is_draft(&snac, edit_id)) {
4357 /* message was previously a draft; it's a create activity */ 4372 /* message was previously a draft; it's a create activity */
4358 4373
4359 /* set the published field to now */ 4374 /* if the date is from the past, overwrite it with right_now */
4360 xs *published = xs_str_utctime(0, ISO_DATE_SPEC); 4375 if (strcmp(xs_dict_get(msg, "published"), right_now) < 0) {
4361 msg = xs_dict_set(msg, "published", published); 4376 snac_debug(&snac, 1, xs_fmt("setting draft ancient date to %s", right_now));
4377 msg = xs_dict_set(msg, "published", right_now);
4378 }
4362 4379
4363 /* overwrite object */ 4380 /* overwrite object */
4364 object_add_ow(edit_id, msg); 4381 object_add_ow(edit_id, msg);
4365 4382
4366 c_msg = msg_create(&snac, msg); 4383 if (future_post) {
4367 timeline_add(&snac, edit_id, msg); 4384 snac_log(&snac, xs_fmt("DUMMY scheduled post 2 %s", edit_id));
4385 }
4386 else {
4387 c_msg = msg_create(&snac, msg);
4388 timeline_add(&snac, edit_id, msg);
4389 }
4390
4368 draft_del(&snac, edit_id); 4391 draft_del(&snac, edit_id);
4369 } 4392 }
4370 else { 4393 else {