commit 1e21c22

default  ·  2025-04-01 03:47:08 +0000 UTC
parent e8b00b3
Some more work for future posts.
1 files changed,  +67, -44
M html.c
M html.c
+67, -44
  1@@ -350,7 +350,7 @@ xs_html *html_note(snac *user, const char *summary,
  2                    const xs_val *mnt_only, const char *redir,
  3                    const char *in_reply_to, int poll,
  4                    const xs_list *att_files, const xs_list *att_alt_texts,
  5-                   int is_draft)
  6+                   int is_draft, const char *published)
  7 /* Yes, this is a FUCKTON of arguments and I'm a bit embarrased */
  8 {
  9     xs *action = xs_fmt("%s/admin/note", user->actor);
 10@@ -440,6 +440,34 @@ xs_html *html_note(snac *user, const char *summary,
 11                 xs_html_attr("name", "is_draft"),
 12                 xs_html_attr(is_draft ? "checked" : "", NULL))));
 13 
 14+    /* post date and time */
 15+    xs *post_date = NULL;
 16+    xs *post_time = NULL;
 17+
 18+    if (xs_is_string(published)) {
 19+        time_t t = xs_parse_iso_date(published, 0);
 20+
 21+        if (t > 0) {
 22+            post_date = xs_str_time(t, "%Y-%m-%d", 1);
 23+            post_time = xs_str_time(t, "%H:%M:%S", 1);
 24+        }
 25+    }
 26+
 27+    xs_html_add(form,
 28+        xs_html_tag("p",
 29+            xs_html_text(L("Post date and time (empty, right now; in the future, schedule for later):")),
 30+            xs_html_sctag("br", NULL),
 31+            xs_html_sctag("input",
 32+                xs_html_attr("type",  "date"),
 33+                xs_html_attr("value", post_date ? post_date : ""),
 34+                xs_html_attr("name",  "post_date")),
 35+            xs_html_text(" "),
 36+            xs_html_sctag("input",
 37+                xs_html_attr("type",  "time"),
 38+                xs_html_attr("value", post_time ? post_time : ""),
 39+                xs_html_attr("step",  "1"),
 40+                xs_html_attr("name",  "post_time"))));
 41+
 42     if (edit_id)
 43         xs_html_add(form,
 44             xs_html_sctag("input",
 45@@ -559,30 +587,6 @@ xs_html *html_note(snac *user, const char *summary,
 46                         xs_html_text(L("End in 1 day"))))));
 47     }
 48 
 49-#if 0
 50-    /* scheduled post data */
 51-    xs *sched_date = xs_dup("");
 52-    xs *sched_time = xs_dup("");
 53-
 54-    xs_html_add(form,
 55-        xs_html_tag("p", NULL),
 56-        xs_html_tag("details",
 57-            xs_html_tag("summary",
 58-                xs_html_text(L("Scheduled post..."))),
 59-            xs_html_tag("p",
 60-                xs_html_text(L("Post date: ")),
 61-                xs_html_sctag("input",
 62-                    xs_html_attr("type", "date"),
 63-                    xs_html_attr("value", sched_date),
 64-                    xs_html_attr("name", "post_date")),
 65-                xs_html_text(" "),
 66-                xs_html_text(L("Post time: ")),
 67-                xs_html_sctag("input",
 68-                    xs_html_attr("type", "time"),
 69-                    xs_html_attr("value", sched_time),
 70-                    xs_html_attr("name", "post_time")))));
 71-#endif
 72-
 73     xs_html_add(form,
 74         xs_html_tag("p", NULL),
 75         xs_html_sctag("input",
 76@@ -1151,7 +1155,7 @@ xs_html *html_top_controls(snac *user)
 77             NULL, NULL,
 78             xs_stock(XSTYPE_FALSE), "",
 79             xs_stock(XSTYPE_FALSE), NULL,
 80-            NULL, 1, NULL, NULL, 0),
 81+            NULL, 1, NULL, NULL, 0, NULL),
 82 
 83         /** operations **/
 84         xs_html_tag("details",
 85@@ -1809,7 +1813,8 @@ xs_html *html_entry_controls(snac *user, const char *actor,
 86                 id, NULL,
 87                 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
 88                 xs_stock(is_msg_public(msg) ? XSTYPE_FALSE : XSTYPE_TRUE), redir,
 89-                NULL, 0, att_files, att_alt_texts, is_draft(user, id))),
 90+                NULL, 0, att_files, att_alt_texts, is_draft(user, id),
 91+                xs_dict_get(msg, "published"))),
 92             xs_html_tag("p", NULL));
 93     }
 94 
 95@@ -1828,7 +1833,7 @@ xs_html *html_entry_controls(snac *user, const char *actor,
 96                 NULL, NULL,
 97                 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
 98                 xs_stock(is_msg_public(msg) ? XSTYPE_FALSE : XSTYPE_TRUE), redir,
 99-                id, 0, NULL, NULL, 0)),
100+                id, 0, NULL, NULL, 0, NULL)),
101             xs_html_tag("p", NULL));
102     }
103 
104@@ -3165,7 +3170,7 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c
105                     NULL, actor_id,
106                     xs_stock(XSTYPE_FALSE), "",
107                     xs_stock(XSTYPE_FALSE), NULL,
108-                    NULL, 0, NULL, NULL, 0),
109+                    NULL, 0, NULL, NULL, 0, NULL),
110                 xs_html_tag("p", NULL));
111 
112             xs_html_add(snac_post, snac_controls);
113@@ -4305,23 +4310,29 @@ int html_post_handler(const xs_dict *req, const char *q_path,
114                 msg = xs_dict_set(msg, "summary",   xs_is_null(summary) ? "..." : summary);
115             }
116 
117-            if (*post_date) {
118-                /* scheduled post */
119-                xs *sched_date = xs_fmt("%sT%s:00", post_date, *post_time ? post_time : "12:00");
120-                time_t t = xs_parse_localtime(sched_date, "%Y-%m-%dT%H:%M:%S");
121+            if (xs_is_string(post_date) && *post_date) {
122+                xs *local_pubdate = xs_fmt("%sT%s", post_date,
123+                    xs_is_string(post_time) && *post_time ? post_time : "00:00:00");
124+
125+                time_t t = xs_parse_iso_date(local_pubdate, 1);
126 
127                 if (t != 0) {
128                     xs *iso_date = xs_str_iso_date(t);
129                     msg = xs_dict_set(msg, "published", iso_date);
130 
131-                    snac_debug(&snac, 1, xs_fmt("Scheduled date: [%s]", iso_date));
132-                }
133-                else {
134-                    snac_log(&snac, xs_fmt("Invalid scheduled date: [%s]", sched_date));
135-                    post_date = "";
136+                    snac_debug(&snac, 1, xs_fmt("Published date: [%s]", iso_date));
137                 }
138+                else
139+                    snac_log(&snac, xs_fmt("Invalid post date: [%s]", local_pubdate));
140             }
141 
142+            /* is the published date from the future? */
143+            int future_post = 0;
144+            xs *right_now = xs_str_utctime(0, ISO_DATE_SPEC);
145+
146+            if (strcmp(xs_dict_get(msg, "published"), right_now) > 0)
147+                future_post = 1;
148+
149             if (xs_is_null(edit_id)) {
150                 /* new message */
151                 const char *id = xs_dict_get(msg, "id");
152@@ -4329,6 +4340,10 @@ int html_post_handler(const xs_dict *req, const char *q_path,
153                 if (store_as_draft) {
154                     draft_add(&snac, id, msg);
155                 }
156+                else
157+                if (future_post) {
158+                    snac_log(&snac, xs_fmt("DUMMY scheduled post 1 %s", id));
159+                }
160                 else {
161                     c_msg = msg_create(&snac, msg);
162                     timeline_add(&snac, id, msg);
163@@ -4340,7 +4355,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
164 
165                 if (valid_status(object_get(edit_id, &p_msg))) {
166                     /* copy relevant fields from previous version */
167-                    char *fields[] = { "id", "context", "url", "published",
168+                    char *fields[] = { "id", "context", "url",
169                                        "to", "inReplyTo", NULL };
170                     int n;
171 
172@@ -4356,15 +4371,23 @@ int html_post_handler(const xs_dict *req, const char *q_path,
173                     if (is_draft(&snac, edit_id)) {
174                         /* message was previously a draft; it's a create activity */
175 
176-                        /* set the published field to now */
177-                        xs *published = xs_str_utctime(0, ISO_DATE_SPEC);
178-                        msg = xs_dict_set(msg, "published", published);
179+                        /* if the date is from the past, overwrite it with right_now */
180+                        if (strcmp(xs_dict_get(msg, "published"), right_now) < 0) {
181+                            snac_debug(&snac, 1, xs_fmt("setting draft ancient date to %s", right_now));
182+                            msg = xs_dict_set(msg, "published", right_now);
183+                        }
184 
185                         /* overwrite object */
186                         object_add_ow(edit_id, msg);
187 
188-                        c_msg = msg_create(&snac, msg);
189-                        timeline_add(&snac, edit_id, msg);
190+                        if (future_post) {
191+                            snac_log(&snac, xs_fmt("DUMMY scheduled post 2 %s", edit_id));
192+                        }
193+                        else {
194+                            c_msg = msg_create(&snac, msg);
195+                            timeline_add(&snac, edit_id, msg);
196+                        }
197+
198                         draft_del(&snac, edit_id);
199                     }
200                     else {