Some tweaks to draft post code.

This commit is contained in:
default 2024-09-14 16:51:30 +02:00
parent 352108e61f
commit e0a2eb4fb5

59
html.c
View File

@ -3136,6 +3136,8 @@ int html_post_handler(const xs_dict *req, const char *q_path,
p_vars = xs_dict_get(req, "p_vars"); p_vars = xs_dict_get(req, "p_vars");
if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/ if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/
snac_debug(&snac, 1, xs_fmt("web action '%s' received", p_path));
/* post note */ /* post note */
const xs_str *content = xs_dict_get(p_vars, "content"); const xs_str *content = xs_dict_get(p_vars, "content");
const xs_str *in_reply_to = xs_dict_get(p_vars, "in_reply_to"); const xs_str *in_reply_to = xs_dict_get(p_vars, "in_reply_to");
@ -3226,27 +3228,22 @@ int html_post_handler(const xs_dict *req, const char *q_path,
msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary); msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary);
} }
if (store_as_draft) {
/* don't send; just store for later */
draft_add(&snac, xs_is_null(edit_id) ? xs_dict_get(msg, "id") : edit_id, msg);
}
else
if (xs_is_null(edit_id)) { if (xs_is_null(edit_id)) {
/* new message */ /* new message */
c_msg = msg_create(&snac, msg); const char *id = xs_dict_get(msg, "id");
timeline_add(&snac, xs_dict_get(msg, "id"), msg);
if (store_as_draft) {
draft_add(&snac, id, msg);
}
else {
c_msg = msg_create(&snac, msg);
timeline_add(&snac, id, msg);
}
} }
else { else {
/* an edition of a previous message */ /* an edition of a previous message */
xs *p_msg = NULL; xs *p_msg = NULL;
if (is_draft(&snac, edit_id)) {
/* message was previously a draft; it's a create activity */
c_msg = msg_create(&snac, msg);
timeline_add(&snac, edit_id, msg);
draft_del(&snac, edit_id);
}
else
if (valid_status(object_get(edit_id, &p_msg))) { if (valid_status(object_get(edit_id, &p_msg))) {
/* copy relevant fields from previous version */ /* copy relevant fields from previous version */
char *fields[] = { "id", "context", "url", "published", char *fields[] = { "id", "context", "url", "published",
@ -3258,15 +3255,35 @@ int html_post_handler(const xs_dict *req, const char *q_path,
msg = xs_dict_set(msg, fields[n], v); msg = xs_dict_set(msg, fields[n], v);
} }
/* set the updated field */ if (store_as_draft) {
xs *updated = xs_str_utctime(0, ISO_DATE_SPEC); draft_add(&snac, edit_id, msg);
msg = xs_dict_set(msg, "updated", updated); }
else
if (is_draft(&snac, edit_id)) {
/* message was previously a draft; it's a create activity */
/* overwrite object, not updating the indexes */ /* set the published field to now */
object_add_ow(edit_id, msg); xs *published = xs_str_utctime(0, ISO_DATE_SPEC);
msg = xs_dict_set(msg, "published", published);
/* update message */ /* overwrite object */
c_msg = msg_update(&snac, msg); object_add_ow(edit_id, msg);
c_msg = msg_create(&snac, msg);
timeline_add(&snac, edit_id, msg);
draft_del(&snac, edit_id);
}
else {
/* set the updated field */
xs *updated = xs_str_utctime(0, ISO_DATE_SPEC);
msg = xs_dict_set(msg, "updated", updated);
/* overwrite object, not updating the indexes */
object_add_ow(edit_id, msg);
/* update message */
c_msg = msg_update(&snac, msg);
}
} }
else else
snac_log(&snac, xs_fmt("cannot get object '%s' for editing", edit_id)); snac_log(&snac, xs_fmt("cannot get object '%s' for editing", edit_id));