diff options
| author | 2024-09-06 09:54:27 +0200 | |
|---|---|---|
| committer | 2024-09-06 09:54:27 +0200 | |
| commit | 7286216f14a8baffff31cdbfa1507c93376e3119 (patch) | |
| tree | 66e1613b57fea3af2f4f890ff898fca00bfae486 | |
| parent | New checkbox in html_note() for marking a post as a draft. (diff) | |
| download | penes-snac2-7286216f14a8baffff31cdbfa1507c93376e3119.tar.gz penes-snac2-7286216f14a8baffff31cdbfa1507c93376e3119.tar.xz penes-snac2-7286216f14a8baffff31cdbfa1507c93376e3119.zip | |
Some new draft functions.
| -rw-r--r-- | data.c | 30 | ||||
| -rw-r--r-- | html.c | 10 | ||||
| -rw-r--r-- | snac.h | 4 |
3 files changed, 40 insertions, 4 deletions
| @@ -1658,6 +1658,36 @@ xs_list *pinned_list(snac *user) | |||
| 1658 | } | 1658 | } |
| 1659 | 1659 | ||
| 1660 | 1660 | ||
| 1661 | /** drafts **/ | ||
| 1662 | |||
| 1663 | int is_draft(snac *user, const char *id) | ||
| 1664 | /* returns true if this note is a draft */ | ||
| 1665 | { | ||
| 1666 | return object_user_cache_in(user, id, "draft"); | ||
| 1667 | } | ||
| 1668 | |||
| 1669 | |||
| 1670 | void draft_del(snac *user, const char *id) | ||
| 1671 | /* delete a message from the draft cache */ | ||
| 1672 | { | ||
| 1673 | object_user_cache_del(user, id, "draft"); | ||
| 1674 | } | ||
| 1675 | |||
| 1676 | |||
| 1677 | void draft_add(snac *user, const char *id, const xs_dict *msg) | ||
| 1678 | /* store the message as a draft */ | ||
| 1679 | { | ||
| 1680 | /* delete from the index, in case it was already there */ | ||
| 1681 | draft_del(user, id); | ||
| 1682 | |||
| 1683 | /* overwrite object */ | ||
| 1684 | object_add_ow(id, msg); | ||
| 1685 | |||
| 1686 | /* [re]add to the index */ | ||
| 1687 | object_user_cache_add(user, id, "draft"); | ||
| 1688 | } | ||
| 1689 | |||
| 1690 | |||
| 1661 | /** hiding **/ | 1691 | /** hiding **/ |
| 1662 | 1692 | ||
| 1663 | xs_str *_hidden_fn(snac *snac, const char *id) | 1693 | xs_str *_hidden_fn(snac *snac, const char *id) |
| @@ -3105,10 +3105,6 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 3105 | 3105 | ||
| 3106 | p_vars = xs_dict_get(req, "p_vars"); | 3106 | p_vars = xs_dict_get(req, "p_vars"); |
| 3107 | 3107 | ||
| 3108 | #if 0 | ||
| 3109 | xs_json_dump(p_vars, 4, stdout); | ||
| 3110 | #endif | ||
| 3111 | |||
| 3112 | if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/ | 3108 | if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/ |
| 3113 | /* post note */ | 3109 | /* post note */ |
| 3114 | const xs_str *content = xs_dict_get(p_vars, "content"); | 3110 | const xs_str *content = xs_dict_get(p_vars, "content"); |
| @@ -3121,6 +3117,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 3121 | const xs_str *edit_id = xs_dict_get(p_vars, "edit_id"); | 3117 | const xs_str *edit_id = xs_dict_get(p_vars, "edit_id"); |
| 3122 | const xs_str *alt_text = xs_dict_get(p_vars, "alt_text"); | 3118 | const xs_str *alt_text = xs_dict_get(p_vars, "alt_text"); |
| 3123 | int priv = !xs_is_null(xs_dict_get(p_vars, "mentioned_only")); | 3119 | 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")); | ||
| 3124 | xs *attach_list = xs_list_new(); | 3121 | xs *attach_list = xs_list_new(); |
| 3125 | 3122 | ||
| 3126 | /* default alt text */ | 3123 | /* default alt text */ |
| @@ -3199,6 +3196,11 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 3199 | msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary); | 3196 | msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary); |
| 3200 | } | 3197 | } |
| 3201 | 3198 | ||
| 3199 | if (is_draft) { | ||
| 3200 | /* don't send; just store for later */ | ||
| 3201 | draft_add(&snac, xs_dict_get(msg, "id"), msg); | ||
| 3202 | } | ||
| 3203 | else | ||
| 3202 | if (xs_is_null(edit_id)) { | 3204 | if (xs_is_null(edit_id)) { |
| 3203 | /* new message */ | 3205 | /* new message */ |
| 3204 | c_msg = msg_create(&snac, msg); | 3206 | c_msg = msg_create(&snac, msg); |
| @@ -178,6 +178,10 @@ int is_pinned(snac *user, const char *id); | |||
| 178 | int is_pinned_by_md5(snac *user, const char *md5); | 178 | int is_pinned_by_md5(snac *user, const char *md5); |
| 179 | xs_list *pinned_list(snac *user); | 179 | xs_list *pinned_list(snac *user); |
| 180 | 180 | ||
| 181 | int is_draft(snac *user, const char *id); | ||
| 182 | void draft_del(snac *user, const char *id); | ||
| 183 | void draft_add(snac *user, const char *id, const xs_dict *msg); | ||
| 184 | |||
| 181 | int limited(snac *user, const char *id, int cmd); | 185 | int limited(snac *user, const char *id, int cmd); |
| 182 | #define is_limited(user, id) limited((user), (id), 0) | 186 | #define is_limited(user, id) limited((user), (id), 0) |
| 183 | #define limit(user, id) limited((user), (id), 1) | 187 | #define limit(user, id) limited((user), (id), 1) |