commit 4b5e945
grunfink
·
2025-09-09 06:33:30 +0000 UTC
parent 7974038
Added support for scheduled posts from the cmdline.
1 files changed,
+29,
-9
M
main.c
M
main.c
+29,
-9
1@@ -808,6 +808,20 @@ int main(int argc, char *argv[])
2 const char *fn = NULL;
3 const char *in_reply_to = NULL;
4 const char **next = NULL;
5+ xs *post_date = NULL;
6+
7+ const char *env_date = getenv("SNAC_POST_DATE");
8+ if (env_date) {
9+ /* convert to ISO */
10+ time_t t = xs_parse_localtime(env_date, "%Y%m%d%H%M%S");
11+
12+ if (t == 0) {
13+ fprintf(stderr, "Invalid $SNAC_POST_DATE format (must be YYYYmmddHHMMSS)\n");
14+ return 1;
15+ }
16+
17+ post_date = xs_str_iso_date(t);
18+ }
19
20 /* iterate possible attachments */
21 while ((fn = GET_ARGV())) {
22@@ -885,7 +899,7 @@ int main(int argc, char *argv[])
23 content = xs_dup(url);
24
25 if (!content || !*content) {
26- printf("Nothing to send\n");
27+ fprintf(stderr, "Nothing to send\n");
28 return 1;
29 }
30
31@@ -896,18 +910,24 @@ int main(int argc, char *argv[])
32 if (strcmp(cmd, "note_unlisted") == 0)
33 scope = 2;
34
35- msg = msg_note(&snac, content, NULL, in_reply_to, attl, scope, getenv("LANG"), NULL);
36+ msg = msg_note(&snac, content, NULL, in_reply_to, attl, scope, getenv("LANG"), post_date);
37
38- c_msg = msg_create(&snac, msg);
39+ const char *id = xs_dict_get(msg, "id");
40
41- if (dbglevel) {
42- xs_json_dump(c_msg, 4, stdout);
43- }
44+ if (post_date)
45+ schedule_add(&snac, id, msg);
46+ else {
47+ c_msg = msg_create(&snac, msg);
48
49- enqueue_message(&snac, c_msg);
50- enqueue_webmention(msg);
51+ if (dbglevel) {
52+ xs_json_dump(c_msg, 4, stdout);
53+ }
54
55- timeline_add(&snac, xs_dict_get(msg, "id"), msg);
56+ enqueue_message(&snac, c_msg);
57+ enqueue_webmention(msg);
58+
59+ timeline_add(&snac, id, msg);
60+ }
61
62 return 0;
63 }