commit 8bd364bd49116b8b335272300ca05f25e1267df7
parent 1434dc277abeb75a2414042a474203a61b73d262
Author: default <nobody@localhost>
Date: Sun, 2 Mar 2025 06:04:52 +0100
msg_note() accepts a nullable post date.
Diffstat:
5 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/activitypub.c b/activitypub.c
@@ -1555,7 +1555,7 @@ xs_dict *msg_follow(snac *snac, const char *q)
xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
const xs_str *in_reply_to, const xs_list *attach,
- int scope, const char *lang_str)
+ int scope, const char *lang_str, const char *msg_date)
/* creates a 'Note' message */
/* scope: 0, public; 1, private (mentioned only); 2, "quiet public"; 3, followers only */
{
@@ -1569,7 +1569,12 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
xs *irt = NULL;
xs *tag = xs_list_new();
xs *atls = xs_list_new();
- xs_dict *msg = msg_base(snac, "Note", id, NULL, "@now", NULL);
+
+ /* discard non-parseable dates */
+ if (!xs_is_string(msg_date) || xs_parse_iso_date(msg_date, 0) == 0)
+ msg_date = NULL;
+
+ xs_dict *msg = msg_base(snac, "Note", id, NULL, xs_or(msg_date, "@now"), NULL);
xs_list *p;
const xs_val *v;
@@ -1782,7 +1787,7 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
const xs_list *opts, int multiple, int end_secs)
/* creates a Question message */
{
- xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL);
+ xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL, NULL);
int max = 8;
xs_set seen;
diff --git a/html.c b/html.c
@@ -4020,7 +4020,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
const char *b64 = xs_dict_get(q_vars, "content");
int sz;
xs *content = xs_base64_dec(b64, &sz);
- xs *msg = msg_note(&snac, content, NULL, NULL, NULL, 0, NULL);
+ xs *msg = msg_note(&snac, content, NULL, NULL, NULL, 0, NULL, NULL);
xs *c_msg = msg_create(&snac, msg);
timeline_add(&snac, xs_dict_get(msg, "id"), msg);
@@ -4220,7 +4220,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs);
}
else
- msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv, NULL);
+ msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv, NULL, NULL);
if (sensitive != NULL) {
msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE));
@@ -4659,7 +4659,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
int c = 0;
while (xs_list_next(ls, &v, &c)) {
- xs *msg = msg_note(&snac, "", actor, irt, NULL, 1, NULL);
+ xs *msg = msg_note(&snac, "", actor, irt, NULL, 1, NULL, NULL);
/* set the option */
msg = xs_dict_append(msg, "name", v);
diff --git a/main.c b/main.c
@@ -710,7 +710,7 @@ int main(int argc, char *argv[])
if (strcmp(cmd, "note_unlisted") == 0)
scope = 2;
- msg = msg_note(&snac, content, NULL, NULL, attl, scope, getenv("LANG"));
+ msg = msg_note(&snac, content, NULL, NULL, attl, scope, getenv("LANG"), NULL);
c_msg = msg_create(&snac, msg);
diff --git a/mastoapi.c b/mastoapi.c
@@ -2628,6 +2628,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
const char *summary = xs_dict_get(args, "spoiler_text");
const char *media_ids = xs_dict_get(args, "media_ids");
const char *language = xs_dict_get(args, "language");
+ const char *sched_date = xs_dict_get(args, "scheduled_at");
if (xs_is_null(media_ids))
media_ids = xs_dict_get(args, "media_ids[]");
@@ -2684,7 +2685,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
if (strcmp(visibility, "public") == 0)
scope = 0;
- xs *msg = msg_note(&snac, content, NULL, irt, attach_list, scope, language);
+ xs *msg = msg_note(&snac, content, NULL, irt, attach_list, scope, language, sched_date);
if (!xs_is_null(summary) && *summary) {
msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE));
@@ -3034,7 +3035,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
if (o) {
const char *name = xs_dict_get(o, "name");
- xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1, NULL);
+ xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1, NULL, NULL);
msg = xs_dict_append(msg, "name", name);
xs *c_msg = msg_create(&snac, msg);
diff --git a/snac.h b/snac.h
@@ -329,7 +329,7 @@ xs_dict *msg_follow(snac *snac, const char *actor);
xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
const xs_str *in_reply_to, const xs_list *attach,
- int scope, const char *lang);
+ int scope, const char *lang_str, const char *msg_date);
xs_dict *msg_undo(snac *snac, const xs_val *object);
xs_dict *msg_delete(snac *snac, const char *id);