summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to 'html.c')
-rw-r--r--html.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/html.c b/html.c
index f271d48..d3c3245 100644
--- a/html.c
+++ b/html.c
@@ -2221,6 +2221,18 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
2221 xs_html_attr("title", L("Bookmarked posts")), 2221 xs_html_attr("title", L("Bookmarked posts")),
2222 xs_html_text("bookmarks")))); 2222 xs_html_text("bookmarks"))));
2223 } 2223 }
2224
2225 {
2226 /* show the list of drafts */
2227 xs *url = xs_fmt("%s/drafts", user->actor);
2228 xs_html_add(lol,
2229 xs_html_tag("li",
2230 xs_html_tag("a",
2231 xs_html_attr("href", url),
2232 xs_html_attr("class", "snac-list-link"),
2233 xs_html_attr("title", L("Post drafts")),
2234 xs_html_text("drafts"))));
2235 }
2224 } 2236 }
2225 2237
2226 if (title) { 2238 if (title) {
@@ -2955,6 +2967,21 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2955 } 2967 }
2956 } 2968 }
2957 else 2969 else
2970 if (strcmp(p_path, "drafts") == 0) { /** list of drafts **/
2971 if (!login(&snac, req)) {
2972 *body = xs_dup(uid);
2973 status = HTTP_STATUS_UNAUTHORIZED;
2974 }
2975 else {
2976 xs *list = draft_list(&snac);
2977
2978 *body = html_timeline(&snac, list, 0, skip, show,
2979 0, L("Post drafts"), "", 0);
2980 *b_size = strlen(*body);
2981 status = HTTP_STATUS_OK;
2982 }
2983 }
2984 else
2958 if (xs_startswith(p_path, "list/")) { /** list timelines **/ 2985 if (xs_startswith(p_path, "list/")) { /** list timelines **/
2959 if (!login(&snac, req)) { 2986 if (!login(&snac, req)) {
2960 *body = xs_dup(uid); 2987 *body = xs_dup(uid);
@@ -3117,7 +3144,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
3117 const xs_str *edit_id = xs_dict_get(p_vars, "edit_id"); 3144 const xs_str *edit_id = xs_dict_get(p_vars, "edit_id");
3118 const xs_str *alt_text = xs_dict_get(p_vars, "alt_text"); 3145 const xs_str *alt_text = xs_dict_get(p_vars, "alt_text");
3119 int priv = !xs_is_null(xs_dict_get(p_vars, "mentioned_only")); 3146 int priv = !xs_is_null(xs_dict_get(p_vars, "mentioned_only"));
3120 int is_draft = !xs_is_null(xs_dict_get(p_vars, "is_draft")); 3147 int store_as_draft = !xs_is_null(xs_dict_get(p_vars, "is_draft"));
3121 xs *attach_list = xs_list_new(); 3148 xs *attach_list = xs_list_new();
3122 3149
3123 /* default alt text */ 3150 /* default alt text */
@@ -3196,9 +3223,9 @@ int html_post_handler(const xs_dict *req, const char *q_path,
3196 msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary); 3223 msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary);
3197 } 3224 }
3198 3225
3199 if (is_draft) { 3226 if (store_as_draft) {
3200 /* don't send; just store for later */ 3227 /* don't send; just store for later */
3201 draft_add(&snac, xs_dict_get(msg, "id"), msg); 3228 draft_add(&snac, xs_is_null(edit_id) ? xs_dict_get(msg, "id") : edit_id, msg);
3202 } 3229 }
3203 else 3230 else
3204 if (xs_is_null(edit_id)) { 3231 if (xs_is_null(edit_id)) {
@@ -3210,6 +3237,13 @@ int html_post_handler(const xs_dict *req, const char *q_path,
3210 /* an edition of a previous message */ 3237 /* an edition of a previous message */
3211 xs *p_msg = NULL; 3238 xs *p_msg = NULL;
3212 3239
3240 if (is_draft(&snac, edit_id)) {
3241 /* message was previously a draft; it's a create activity */
3242 c_msg = msg_create(&snac, msg);
3243 timeline_add(&snac, edit_id, msg);
3244 draft_del(&snac, edit_id);
3245 }
3246 else
3213 if (valid_status(object_get(edit_id, &p_msg))) { 3247 if (valid_status(object_get(edit_id, &p_msg))) {
3214 /* copy relevant fields from previous version */ 3248 /* copy relevant fields from previous version */
3215 char *fields[] = { "id", "context", "url", "published", 3249 char *fields[] = { "id", "context", "url", "published",
@@ -3383,7 +3417,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
3383 } 3417 }
3384 else { 3418 else {
3385 /* delete an entry */ 3419 /* delete an entry */
3386 if (xs_startswith(id, snac.actor)) { 3420 if (xs_startswith(id, snac.actor) && !is_draft(&snac, id)) {
3387 /* it's a post by us: generate a delete */ 3421 /* it's a post by us: generate a delete */
3388 xs *msg = msg_delete(&snac, id); 3422 xs *msg = msg_delete(&snac, id);
3389 3423
@@ -3394,6 +3428,8 @@ int html_post_handler(const xs_dict *req, const char *q_path,
3394 3428
3395 timeline_del(&snac, id); 3429 timeline_del(&snac, id);
3396 3430
3431 draft_del(&snac, id);
3432
3397 snac_log(&snac, xs_fmt("deleted entry %s", id)); 3433 snac_log(&snac, xs_fmt("deleted entry %s", id));
3398 } 3434 }
3399 } 3435 }