mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
Some tweaks to draft post code.
This commit is contained in:
parent
352108e61f
commit
e0a2eb4fb5
43
html.c
43
html.c
@ -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 */
|
||||||
|
const char *id = xs_dict_get(msg, "id");
|
||||||
|
|
||||||
|
if (store_as_draft) {
|
||||||
|
draft_add(&snac, id, msg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
c_msg = msg_create(&snac, msg);
|
c_msg = msg_create(&snac, msg);
|
||||||
timeline_add(&snac, xs_dict_get(msg, "id"), 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,6 +3255,25 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (store_as_draft) {
|
||||||
|
draft_add(&snac, edit_id, msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (is_draft(&snac, edit_id)) {
|
||||||
|
/* message was previously a draft; it's a create activity */
|
||||||
|
|
||||||
|
/* set the published field to now */
|
||||||
|
xs *published = xs_str_utctime(0, ISO_DATE_SPEC);
|
||||||
|
msg = xs_dict_set(msg, "published", published);
|
||||||
|
|
||||||
|
/* overwrite object */
|
||||||
|
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 */
|
/* set the updated field */
|
||||||
xs *updated = xs_str_utctime(0, ISO_DATE_SPEC);
|
xs *updated = xs_str_utctime(0, ISO_DATE_SPEC);
|
||||||
msg = xs_dict_set(msg, "updated", updated);
|
msg = xs_dict_set(msg, "updated", updated);
|
||||||
@ -3268,6 +3284,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
|
|||||||
/* update message */
|
/* update message */
|
||||||
c_msg = msg_update(&snac, msg);
|
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));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user