commit ac0c7bc

default  ·  2024-09-06 08:31:09 +0000 UTC
parent 7286216
More work in post drafts.
3 files changed,  +48, -4
M data.c
M html.c
M snac.h
M data.c
+7, -0
 1@@ -1688,6 +1688,13 @@ void draft_add(snac *user, const char *id, const xs_dict *msg)
 2 }
 3 
 4 
 5+xs_list *draft_list(snac *user)
 6+/* return the lists of drafts */
 7+{
 8+    return object_user_cache_list(user, "draft", XS_ALL, 1);
 9+}
10+
11+
12 /** hiding **/
13 
14 xs_str *_hidden_fn(snac *snac, const char *id)
M html.c
+40, -4
 1@@ -2221,6 +2221,18 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
 2                         xs_html_attr("title", L("Bookmarked posts")),
 3                         xs_html_text("bookmarks"))));
 4         }
 5+
 6+        {
 7+            /* show the list of drafts */
 8+            xs *url = xs_fmt("%s/drafts", user->actor);
 9+            xs_html_add(lol,
10+                xs_html_tag("li",
11+                    xs_html_tag("a",
12+                        xs_html_attr("href", url),
13+                        xs_html_attr("class", "snac-list-link"),
14+                        xs_html_attr("title", L("Post drafts")),
15+                        xs_html_text("drafts"))));
16+        }
17     }
18 
19     if (title) {
20@@ -2955,6 +2967,21 @@ int html_get_handler(const xs_dict *req, const char *q_path,
21         }
22     }
23     else
24+    if (strcmp(p_path, "drafts") == 0) { /** list of drafts **/
25+        if (!login(&snac, req)) {
26+            *body  = xs_dup(uid);
27+            status = HTTP_STATUS_UNAUTHORIZED;
28+        }
29+        else {
30+            xs *list = draft_list(&snac);
31+
32+            *body = html_timeline(&snac, list, 0, skip, show,
33+                0, L("Post drafts"), "", 0);
34+            *b_size = strlen(*body);
35+            status  = HTTP_STATUS_OK;
36+        }
37+    }
38+    else
39     if (xs_startswith(p_path, "list/")) { /** list timelines **/
40         if (!login(&snac, req)) {
41             *body  = xs_dup(uid);
42@@ -3117,7 +3144,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
43         const xs_str *edit_id      = xs_dict_get(p_vars, "edit_id");
44         const xs_str *alt_text     = xs_dict_get(p_vars, "alt_text");
45         int priv             = !xs_is_null(xs_dict_get(p_vars, "mentioned_only"));
46-        int is_draft         = !xs_is_null(xs_dict_get(p_vars, "is_draft"));
47+        int store_as_draft   = !xs_is_null(xs_dict_get(p_vars, "is_draft"));
48         xs *attach_list      = xs_list_new();
49 
50         /* default alt text */
51@@ -3196,9 +3223,9 @@ int html_post_handler(const xs_dict *req, const char *q_path,
52                 msg = xs_dict_set(msg, "summary",   xs_is_null(summary) ? "..." : summary);
53             }
54 
55-            if (is_draft) {
56+            if (store_as_draft) {
57                 /* don't send; just store for later */
58-                draft_add(&snac, xs_dict_get(msg, "id"), msg);
59+                draft_add(&snac, xs_is_null(edit_id) ? xs_dict_get(msg, "id") : edit_id, msg);
60             }
61             else
62             if (xs_is_null(edit_id)) {
63@@ -3210,6 +3237,13 @@ int html_post_handler(const xs_dict *req, const char *q_path,
64                 /* an edition of a previous message */
65                 xs *p_msg = NULL;
66 
67+                if (is_draft(&snac, edit_id)) {
68+                    /* message was previously a draft; it's a create activity */
69+                    c_msg = msg_create(&snac, msg);
70+                    timeline_add(&snac, edit_id, msg);
71+                    draft_del(&snac, edit_id);
72+                }
73+                else
74                 if (valid_status(object_get(edit_id, &p_msg))) {
75                     /* copy relevant fields from previous version */
76                     char *fields[] = { "id", "context", "url", "published",
77@@ -3383,7 +3417,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
78             }
79             else {
80                 /* delete an entry */
81-                if (xs_startswith(id, snac.actor)) {
82+                if (xs_startswith(id, snac.actor) && !is_draft(&snac, id)) {
83                     /* it's a post by us: generate a delete */
84                     xs *msg = msg_delete(&snac, id);
85 
86@@ -3394,6 +3428,8 @@ int html_post_handler(const xs_dict *req, const char *q_path,
87 
88                 timeline_del(&snac, id);
89 
90+                draft_del(&snac, id);
91+
92                 snac_log(&snac, xs_fmt("deleted entry %s", id));
93             }
94         }
M snac.h
+1, -0
1@@ -181,6 +181,7 @@ xs_list *pinned_list(snac *user);
2 int is_draft(snac *user, const char *id);
3 void draft_del(snac *user, const char *id);
4 void draft_add(snac *user, const char *id, const xs_dict *msg);
5+xs_list *draft_list(snac *user);
6 
7 int limited(snac *user, const char *id, int cmd);
8 #define is_limited(user, id) limited((user), (id), 0)