Add an option to always show sensitive content

- add a cw key to user.json
- add a cw checkbox to user setup form
- handle the cw parameter when updating user setup
- when rendering an entry, look at the cw config: if set, use a h3
  heading for the summary; otherwise use details + summar + SENSITIVE
  CONTENT like before
This commit is contained in:
Alex Schroeder 2022-12-02 09:55:25 +01:00
parent 4b6e1df907
commit e4c26715a1
2 changed files with 23 additions and 6 deletions

22
html.c
View file

@ -277,6 +277,9 @@ d_char *html_top_controls(snac *snac, d_char *s)
"<p>%s:<br>\n" "<p>%s:<br>\n"
"<textarea name=\"bio\" cols=\"40\" rows=\"4\">%s</textarea></p>\n" "<textarea name=\"bio\" cols=\"40\" rows=\"4\">%s</textarea></p>\n"
"<p><input type=\"checkbox\" name=\"cw\" id=\"cw\" %s>\n"
"<label for=\"cw\">%s</label></p>\n"
"<p>%s:<br>\n" "<p>%s:<br>\n"
"<input type=\"text\" name=\"email\" value=\"%s\"></p>\n" "<input type=\"text\" name=\"email\" value=\"%s\"></p>\n"
@ -320,6 +323,8 @@ d_char *html_top_controls(snac *snac, d_char *s)
xs_dict_get(snac->config, "avatar"), xs_dict_get(snac->config, "avatar"),
L("Bio"), L("Bio"),
xs_dict_get(snac->config, "bio"), xs_dict_get(snac->config, "bio"),
xs_dict_get(snac->config, "cw"),
L("Always show sensitive content"),
L("Email address for notifications"), L("Email address for notifications"),
email, email,
L("Password (only to change it)"), L("Password (only to change it)"),
@ -613,12 +618,18 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, int
if (!xs_is_null(v = xs_dict_get(msg, "sensitive")) && xs_type(v) == XSTYPE_TRUE) { if (!xs_is_null(v = xs_dict_get(msg, "sensitive")) && xs_type(v) == XSTYPE_TRUE) {
if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0') if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0')
v = "..."; v = "...";
char *cw = xs_dict_get(snac->config, "cw");
if (xs_is_null(cw))
cw = "";
if (strcmp(cw, "checked") == 0) {
xs *s1 = xs_fmt("<h3>%s</h3>", v);
s = xs_str_cat(s, s1);
} else {
xs *s1 = xs_fmt("<details><summary>%s [%s]</summary>\n", v, L("SENSITIVE CONTENT")); xs *s1 = xs_fmt("<details><summary>%s [%s]</summary>\n", v, L("SENSITIVE CONTENT"));
s = xs_str_cat(s, s1); s = xs_str_cat(s, s1);
sensitive = 1; sensitive = 1;
} }
}
#if 0 #if 0
{ {
@ -1379,6 +1390,12 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
snac.config = xs_dict_set(snac.config, "avatar", v); snac.config = xs_dict_set(snac.config, "avatar", v);
if ((v = xs_dict_get(p_vars, "bio")) != NULL) if ((v = xs_dict_get(p_vars, "bio")) != NULL)
snac.config = xs_dict_set(snac.config, "bio", v); snac.config = xs_dict_set(snac.config, "bio", v);
if ((v = xs_dict_get(p_vars, "cw")) != NULL &&
strcmp(v, "on") == 0) {
snac.config = xs_dict_set(snac.config, "cw", "checked");
} else { /* if the checkbox is not set, the parameter is missing */
snac.config = xs_dict_set(snac.config, "cw", "");
}
if ((v = xs_dict_get(p_vars, "email")) != NULL) if ((v = xs_dict_get(p_vars, "email")) != NULL)
snac.config = xs_dict_set(snac.config, "email", v); snac.config = xs_dict_set(snac.config, "email", v);
@ -1428,4 +1445,3 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
return status; return status;
} }

View file

@ -226,6 +226,7 @@ int adduser(char *uid)
config = xs_dict_append(config, "name", uid); config = xs_dict_append(config, "name", uid);
config = xs_dict_append(config, "avatar", ""); config = xs_dict_append(config, "avatar", "");
config = xs_dict_append(config, "bio", ""); config = xs_dict_append(config, "bio", "");
config = xs_dict_append(config, "cw", "");
config = xs_dict_append(config, "published", date); config = xs_dict_append(config, "published", date);
config = xs_dict_append(config, "passwd", pwd_f); config = xs_dict_append(config, "passwd", pwd_f);