summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2024-09-14 16:51:30 +0200
committerGravatar default2024-09-14 16:51:30 +0200
commite0a2eb4fb572a93a4d75c4efbb2ef22dd82f9cc6 (patch)
tree0bddfb77708cce165f66072219e1b6ad3ae8fc00
parentSet the "Only for mentioned people" checkbox properly. (diff)
downloadpenes-snac2-e0a2eb4fb572a93a4d75c4efbb2ef22dd82f9cc6.tar.gz
penes-snac2-e0a2eb4fb572a93a4d75c4efbb2ef22dd82f9cc6.tar.xz
penes-snac2-e0a2eb4fb572a93a4d75c4efbb2ef22dd82f9cc6.zip
Some tweaks to draft post code.
-rw-r--r--html.c59
1 files changed, 38 insertions, 21 deletions
diff --git a/html.c b/html.c
index 272a26e..aced4ad 100644
--- a/html.c
+++ b/html.c
@@ -3136,6 +3136,8 @@ int html_post_handler(const xs_dict *req, const char *q_path,
3136 p_vars = xs_dict_get(req, "p_vars"); 3136 p_vars = xs_dict_get(req, "p_vars");
3137 3137
3138 if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/ 3138 if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/
3139 snac_debug(&snac, 1, xs_fmt("web action '%s' received", p_path));
3140
3139 /* post note */ 3141 /* post note */
3140 const xs_str *content = xs_dict_get(p_vars, "content"); 3142 const xs_str *content = xs_dict_get(p_vars, "content");
3141 const xs_str *in_reply_to = xs_dict_get(p_vars, "in_reply_to"); 3143 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,
3226 msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary); 3228 msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary);
3227 } 3229 }
3228 3230
3229 if (store_as_draft) {
3230 /* don't send; just store for later */
3231 draft_add(&snac, xs_is_null(edit_id) ? xs_dict_get(msg, "id") : edit_id, msg);
3232 }
3233 else
3234 if (xs_is_null(edit_id)) { 3231 if (xs_is_null(edit_id)) {
3235 /* new message */ 3232 /* new message */
3236 c_msg = msg_create(&snac, msg); 3233 const char *id = xs_dict_get(msg, "id");
3237 timeline_add(&snac, xs_dict_get(msg, "id"), msg); 3234
3235 if (store_as_draft) {
3236 draft_add(&snac, id, msg);
3237 }
3238 else {
3239 c_msg = msg_create(&snac, msg);
3240 timeline_add(&snac, id, msg);
3241 }
3238 } 3242 }
3239 else { 3243 else {
3240 /* an edition of a previous message */ 3244 /* an edition of a previous message */
3241 xs *p_msg = NULL; 3245 xs *p_msg = NULL;
3242 3246
3243 if (is_draft(&snac, edit_id)) {
3244 /* message was previously a draft; it's a create activity */
3245 c_msg = msg_create(&snac, msg);
3246 timeline_add(&snac, edit_id, msg);
3247 draft_del(&snac, edit_id);
3248 }
3249 else
3250 if (valid_status(object_get(edit_id, &p_msg))) { 3247 if (valid_status(object_get(edit_id, &p_msg))) {
3251 /* copy relevant fields from previous version */ 3248 /* copy relevant fields from previous version */
3252 char *fields[] = { "id", "context", "url", "published", 3249 char *fields[] = { "id", "context", "url", "published",
@@ -3258,15 +3255,35 @@ int html_post_handler(const xs_dict *req, const char *q_path,
3258 msg = xs_dict_set(msg, fields[n], v); 3255 msg = xs_dict_set(msg, fields[n], v);
3259 } 3256 }
3260 3257
3261 /* set the updated field */ 3258 if (store_as_draft) {
3262 xs *updated = xs_str_utctime(0, ISO_DATE_SPEC); 3259 draft_add(&snac, edit_id, msg);
3263 msg = xs_dict_set(msg, "updated", updated); 3260 }
3261 else
3262 if (is_draft(&snac, edit_id)) {
3263 /* message was previously a draft; it's a create activity */
3264 3264
3265 /* overwrite object, not updating the indexes */ 3265 /* set the published field to now */
3266 object_add_ow(edit_id, msg); 3266 xs *published = xs_str_utctime(0, ISO_DATE_SPEC);
3267 msg = xs_dict_set(msg, "published", published);
3267 3268
3268 /* update message */ 3269 /* overwrite object */
3269 c_msg = msg_update(&snac, msg); 3270 object_add_ow(edit_id, msg);
3271
3272 c_msg = msg_create(&snac, msg);
3273 timeline_add(&snac, edit_id, msg);
3274 draft_del(&snac, edit_id);
3275 }
3276 else {
3277 /* set the updated field */
3278 xs *updated = xs_str_utctime(0, ISO_DATE_SPEC);
3279 msg = xs_dict_set(msg, "updated", updated);
3280
3281 /* overwrite object, not updating the indexes */
3282 object_add_ow(edit_id, msg);
3283
3284 /* update message */
3285 c_msg = msg_update(&snac, msg);
3286 }
3270 } 3287 }
3271 else 3288 else
3272 snac_log(&snac, xs_fmt("cannot get object '%s' for editing", edit_id)); 3289 snac_log(&snac, xs_fmt("cannot get object '%s' for editing", edit_id));