commit 8bd364b

default  ·  2025-03-02 05:04:52 +0000 UTC
parent 1434dc2
msg_note() accepts a nullable post date.
5 files changed,  +16, -10
M html.c
M main.c
M snac.h
+8, -3
 1@@ -1555,7 +1555,7 @@ xs_dict *msg_follow(snac *snac, const char *q)
 2 
 3 xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
 4                   const xs_str *in_reply_to, const xs_list *attach,
 5-                  int scope, const char *lang_str)
 6+                  int scope, const char *lang_str, const char *msg_date)
 7 /* creates a 'Note' message */
 8 /* scope: 0, public; 1, private (mentioned only); 2, "quiet public"; 3, followers only */
 9 {
10@@ -1569,7 +1569,12 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
11     xs *irt  = NULL;
12     xs *tag  = xs_list_new();
13     xs *atls = xs_list_new();
14-    xs_dict *msg = msg_base(snac, "Note", id, NULL, "@now", NULL);
15+
16+    /* discard non-parseable dates */
17+    if (!xs_is_string(msg_date) || xs_parse_iso_date(msg_date, 0) == 0)
18+        msg_date = NULL;
19+
20+    xs_dict *msg = msg_base(snac, "Note", id, NULL, xs_or(msg_date, "@now"), NULL);
21     xs_list *p;
22     const xs_val *v;
23 
24@@ -1782,7 +1787,7 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
25                       const xs_list *opts, int multiple, int end_secs)
26 /* creates a Question message */
27 {
28-    xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL);
29+    xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL, NULL);
30     int max      = 8;
31     xs_set seen;
32 
M html.c
+3, -3
 1@@ -4020,7 +4020,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
 2             const char *b64 = xs_dict_get(q_vars, "content");
 3             int sz;
 4             xs *content = xs_base64_dec(b64, &sz);
 5-            xs *msg = msg_note(&snac, content, NULL, NULL, NULL, 0, NULL);
 6+            xs *msg = msg_note(&snac, content, NULL, NULL, NULL, 0, NULL, NULL);
 7             xs *c_msg = msg_create(&snac, msg);
 8 
 9             timeline_add(&snac, xs_dict_get(msg, "id"), msg);
10@@ -4220,7 +4220,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
11                 enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs);
12             }
13             else
14-                msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv, NULL);
15+                msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv, NULL, NULL);
16 
17             if (sensitive != NULL) {
18                 msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE));
19@@ -4659,7 +4659,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
20         int c = 0;
21 
22         while (xs_list_next(ls, &v, &c)) {
23-            xs *msg = msg_note(&snac, "", actor, irt, NULL, 1, NULL);
24+            xs *msg = msg_note(&snac, "", actor, irt, NULL, 1, NULL, NULL);
25 
26             /* set the option */
27             msg = xs_dict_append(msg, "name", v);
M main.c
+1, -1
1@@ -710,7 +710,7 @@ int main(int argc, char *argv[])
2         if (strcmp(cmd, "note_unlisted") == 0)
3             scope = 2;
4 
5-        msg = msg_note(&snac, content, NULL, NULL, attl, scope, getenv("LANG"));
6+        msg = msg_note(&snac, content, NULL, NULL, attl, scope, getenv("LANG"), NULL);
7 
8         c_msg = msg_create(&snac, msg);
9 
+3, -2
 1@@ -2628,6 +2628,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
 2             const char *summary    = xs_dict_get(args, "spoiler_text");
 3             const char *media_ids  = xs_dict_get(args, "media_ids");
 4             const char *language   = xs_dict_get(args, "language");
 5+            const char *sched_date = xs_dict_get(args, "scheduled_at");
 6 
 7             if (xs_is_null(media_ids))
 8                 media_ids = xs_dict_get(args, "media_ids[]");
 9@@ -2684,7 +2685,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
10             if (strcmp(visibility, "public") == 0)
11                 scope = 0;
12 
13-            xs *msg = msg_note(&snac, content, NULL, irt, attach_list, scope, language);
14+            xs *msg = msg_note(&snac, content, NULL, irt, attach_list, scope, language, sched_date);
15 
16             if (!xs_is_null(summary) && *summary) {
17                 msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE));
18@@ -3034,7 +3035,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
19                                 if (o) {
20                                     const char *name = xs_dict_get(o, "name");
21 
22-                                    xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1, NULL);
23+                                    xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1, NULL, NULL);
24                                     msg = xs_dict_append(msg, "name", name);
25 
26                                     xs *c_msg = msg_create(&snac, msg);
M snac.h
+1, -1
1@@ -329,7 +329,7 @@ xs_dict *msg_follow(snac *snac, const char *actor);
2 
3 xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
4                   const xs_str *in_reply_to, const xs_list *attach,
5-                  int scope, const char *lang);
6+                  int scope, const char *lang_str, const char *msg_date);
7 
8 xs_dict *msg_undo(snac *snac, const xs_val *object);
9 xs_dict *msg_delete(snac *snac, const char *id);