Some new draft functions.

This commit is contained in:
default 2024-09-06 09:54:27 +02:00
parent 97c4af001b
commit 7286216f14
3 changed files with 40 additions and 4 deletions

30
data.c
View file

@ -1658,6 +1658,36 @@ xs_list *pinned_list(snac *user)
}
/** drafts **/
int is_draft(snac *user, const char *id)
/* returns true if this note is a draft */
{
return object_user_cache_in(user, id, "draft");
}
void draft_del(snac *user, const char *id)
/* delete a message from the draft cache */
{
object_user_cache_del(user, id, "draft");
}
void draft_add(snac *user, const char *id, const xs_dict *msg)
/* store the message as a draft */
{
/* delete from the index, in case it was already there */
draft_del(user, id);
/* overwrite object */
object_add_ow(id, msg);
/* [re]add to the index */
object_user_cache_add(user, id, "draft");
}
/** hiding **/
xs_str *_hidden_fn(snac *snac, const char *id)

10
html.c
View file

@ -3105,10 +3105,6 @@ int html_post_handler(const xs_dict *req, const char *q_path,
p_vars = xs_dict_get(req, "p_vars");
#if 0
xs_json_dump(p_vars, 4, stdout);
#endif
if (p_path && strcmp(p_path, "admin/note") == 0) { /** **/
/* post note */
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,
const xs_str *edit_id = xs_dict_get(p_vars, "edit_id");
const xs_str *alt_text = xs_dict_get(p_vars, "alt_text");
int priv = !xs_is_null(xs_dict_get(p_vars, "mentioned_only"));
int is_draft = !xs_is_null(xs_dict_get(p_vars, "is_draft"));
xs *attach_list = xs_list_new();
/* default alt text */
@ -3199,6 +3196,11 @@ int html_post_handler(const xs_dict *req, const char *q_path,
msg = xs_dict_set(msg, "summary", xs_is_null(summary) ? "..." : summary);
}
if (is_draft) {
/* don't send; just store for later */
draft_add(&snac, xs_dict_get(msg, "id"), msg);
}
else
if (xs_is_null(edit_id)) {
/* new message */
c_msg = msg_create(&snac, msg);

4
snac.h
View file

@ -178,6 +178,10 @@ int is_pinned(snac *user, const char *id);
int is_pinned_by_md5(snac *user, const char *md5);
xs_list *pinned_list(snac *user);
int is_draft(snac *user, const char *id);
void draft_del(snac *user, const char *id);
void draft_add(snac *user, const char *id, const xs_dict *msg);
int limited(snac *user, const char *id, int cmd);
#define is_limited(user, id) limited((user), (id), 0)
#define limit(user, id) limited((user), (id), 1)