From 8b252dab84e45de924fb55ef9a85131769c477bc Mon Sep 17 00:00:00 2001 From: default Date: Fri, 4 Nov 2022 08:48:15 +0100 Subject: [PATCH] New 'Hide' button. --- data.c | 31 +++++++++++++++++++++++++++++++ html.c | 13 ++++++++++++- snac.h | 1 + utils.c | 1 + 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/data.c b/data.c index e8e4f9f..741acc8 100644 --- a/data.c +++ b/data.c @@ -627,6 +627,37 @@ void timeline_admire(snac *snac, char *id, char *admirer, int like) } +int timeline_hide(snac *snac, char *id, int hide) +/* hides/unhides a timeline entry */ +{ + int ret = 0; + xs *fn = _timeline_find_fn(snac, id); + FILE *f; + + if (fn != NULL && (f = fopen(fn, "r")) != NULL) { + xs *s1 = xs_readall(f); + xs *msg = xs_json_loads(s1); + xs *meta = xs_dup(xs_dict_get(msg, "_snac")); + + fclose(f); + + meta = xs_dict_set(meta, "hidden", xs_val_new(hide ? XSTYPE_TRUE : XSTYPE_FALSE)); + msg = xs_dict_set(msg, "_snac", meta); + + if ((f = fopen(fn, "w")) != NULL) { + xs *j1 = xs_json_dumps_pp(msg, 4); + + fwrite(j1, strlen(j1), 1, f); + fclose(f); + + ret = 1; + } + } + + return ret; +} + + d_char *_following_fn(snac *snac, char *actor) { xs *md5 = xs_md5_hex(actor, strlen(actor)); diff --git a/html.c b/html.c index afeb5df..53f82cb 100644 --- a/html.c +++ b/html.c @@ -435,6 +435,7 @@ d_char *html_entry_controls(snac *snac, d_char *os, char *msg, int num) s = html_button(s, "mute", L("MUTE")); } + s = html_button(s, "hide", L("Hide")); s = html_button(s, "delete", L("Delete")); s = xs_str_cat(s, "\n"); @@ -489,6 +490,12 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i xs *s = xs_str_new(NULL); + /* top wrap */ + if ((v = xs_dict_get(meta, "hidden")) && xs_type(v) == XSTYPE_TRUE) + s = xs_str_cat(s, "
\n"); + else + s = xs_str_cat(s, "
\n"); + if (level == 0) { xs *s1 = xs_fmt("\n", *num); @@ -738,7 +745,7 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, xs_set *seen, int local, i s = xs_str_cat(s, "
\n"); } - s = xs_str_cat(s, "
\n"); + s = xs_str_cat(s, "\n\n"); return xs_str_cat(os, s); } @@ -1194,6 +1201,10 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, unmute(&snac, actor); } else + if (strcmp(action, L("Hide")) == 0) { + timeline_hide(&snac, id, 1); + } + else if (strcmp(action, L("Follow")) == 0) { xs *msg = msg_follow(&snac, actor); diff --git a/snac.h b/snac.h index c25e9a8..b65a86a 100644 --- a/snac.h +++ b/snac.h @@ -65,6 +65,7 @@ d_char *timeline_get(snac *snac, char *fn); d_char *timeline_list(snac *snac, int max); int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer); void timeline_admire(snac *snac, char *id, char *admirer, int like); +int timeline_hide(snac *snac, char *id, int hide); d_char *local_list(snac *snac, int max); diff --git a/utils.c b/utils.c index 55b8758..e0ca276 100644 --- a/utils.c +++ b/utils.c @@ -46,6 +46,7 @@ const char *default_css = ".snac-btn-unmute { float: right; margin-left: 0.5em }\n" ".snac-btn-follow { float: right; margin-left: 0.5em }\n" ".snac-btn-unfollow { float: right; margin-left: 0.5em }\n" + ".snac-btn-hide { float: right; margin-left: 0.5em }\n" ".snac-btn-delete { float: right; margin-left: 0.5em }\n" ".snac-footer { margin-top: 2em; font-size: 75% }\n";