commit e0a2eb4
default
·
2024-09-14 14:51:30 +0000 UTC
parent 352108e
Some tweaks to draft post code.
1 files changed,
+38,
-21
M
html.c
M
html.c
+38,
-21
1@@ -3136,6 +3136,8 @@ int html_post_handler(const xs_dict *req, const char *q_path,
2 p_vars = xs_dict_get(req, "p_vars");
3
4 if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/
5+ snac_debug(&snac, 1, xs_fmt("web action '%s' received", p_path));
6+
7 /* post note */
8 const xs_str *content = xs_dict_get(p_vars, "content");
9 const xs_str *in_reply_to = xs_dict_get(p_vars, "in_reply_to");
10@@ -3226,27 +3228,22 @@ int html_post_handler(const xs_dict *req, const char *q_path,
11 msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary);
12 }
13
14- if (store_as_draft) {
15- /* don't send; just store for later */
16- draft_add(&snac, xs_is_null(edit_id) ? xs_dict_get(msg, "id") : edit_id, msg);
17- }
18- else
19 if (xs_is_null(edit_id)) {
20 /* new message */
21- c_msg = msg_create(&snac, msg);
22- timeline_add(&snac, xs_dict_get(msg, "id"), msg);
23+ const char *id = xs_dict_get(msg, "id");
24+
25+ if (store_as_draft) {
26+ draft_add(&snac, id, msg);
27+ }
28+ else {
29+ c_msg = msg_create(&snac, msg);
30+ timeline_add(&snac, id, msg);
31+ }
32 }
33 else {
34 /* an edition of a previous message */
35 xs *p_msg = NULL;
36
37- if (is_draft(&snac, edit_id)) {
38- /* message was previously a draft; it's a create activity */
39- c_msg = msg_create(&snac, msg);
40- timeline_add(&snac, edit_id, msg);
41- draft_del(&snac, edit_id);
42- }
43- else
44 if (valid_status(object_get(edit_id, &p_msg))) {
45 /* copy relevant fields from previous version */
46 char *fields[] = { "id", "context", "url", "published",
47@@ -3258,15 +3255,35 @@ int html_post_handler(const xs_dict *req, const char *q_path,
48 msg = xs_dict_set(msg, fields[n], v);
49 }
50
51- /* set the updated field */
52- xs *updated = xs_str_utctime(0, ISO_DATE_SPEC);
53- msg = xs_dict_set(msg, "updated", updated);
54+ if (store_as_draft) {
55+ draft_add(&snac, edit_id, msg);
56+ }
57+ else
58+ if (is_draft(&snac, edit_id)) {
59+ /* message was previously a draft; it's a create activity */
60
61- /* overwrite object, not updating the indexes */
62- object_add_ow(edit_id, msg);
63+ /* set the published field to now */
64+ xs *published = xs_str_utctime(0, ISO_DATE_SPEC);
65+ msg = xs_dict_set(msg, "published", published);
66
67- /* update message */
68- c_msg = msg_update(&snac, msg);
69+ /* overwrite object */
70+ object_add_ow(edit_id, msg);
71+
72+ c_msg = msg_create(&snac, msg);
73+ timeline_add(&snac, edit_id, msg);
74+ draft_del(&snac, edit_id);
75+ }
76+ else {
77+ /* set the updated field */
78+ xs *updated = xs_str_utctime(0, ISO_DATE_SPEC);
79+ msg = xs_dict_set(msg, "updated", updated);
80+
81+ /* overwrite object, not updating the indexes */
82+ object_add_ow(edit_id, msg);
83+
84+ /* update message */
85+ c_msg = msg_update(&snac, msg);
86+ }
87 }
88 else
89 snac_log(&snac, xs_fmt("cannot get object '%s' for editing", edit_id));