New 'Hide' button.

This commit is contained in:
default 2022-11-04 08:48:15 +01:00
parent b6a2abede2
commit 8b252dab84
4 changed files with 45 additions and 1 deletions

31
data.c
View file

@ -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));

13
html.c
View file

@ -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, "</form>\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, "<div style=\"display: none\">\n");
else
s = xs_str_cat(s, "<div>\n");
if (level == 0) {
xs *s1 = xs_fmt("<a name=\"%d_entry\"></a>\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, "</div>\n");
}
s = xs_str_cat(s, "</div>\n");
s = xs_str_cat(s, "</div>\n</div>\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);

1
snac.h
View file

@ -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);

View file

@ -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";