commit e4c2671

Alex Schroeder  ·  2022-12-02 08:55:25 +0000 UTC
parent 4b6e1df
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
2 files changed,  +23, -6
M html.c
M html.c
+22, -6
 1@@ -277,6 +277,9 @@ d_char *html_top_controls(snac *snac, d_char *s)
 2         "<p>%s:<br>\n"
 3         "<textarea name=\"bio\" cols=\"40\" rows=\"4\">%s</textarea></p>\n"
 4 
 5+        "<p><input type=\"checkbox\" name=\"cw\" id=\"cw\" %s>\n"
 6+        "<label for=\"cw\">%s</label></p>\n"
 7+
 8         "<p>%s:<br>\n"
 9         "<input type=\"text\" name=\"email\" value=\"%s\"></p>\n"
10 
11@@ -320,6 +323,8 @@ d_char *html_top_controls(snac *snac, d_char *s)
12         xs_dict_get(snac->config, "avatar"),
13         L("Bio"),
14         xs_dict_get(snac->config, "bio"),
15+        xs_dict_get(snac->config, "cw"),
16+        L("Always show sensitive content"),
17         L("Email address for notifications"),
18         email,
19         L("Password (only to change it)"),
20@@ -613,11 +618,17 @@ d_char *html_entry(snac *snac, d_char *os, char *msg, int local, int level, int
21     if (!xs_is_null(v = xs_dict_get(msg, "sensitive")) && xs_type(v) == XSTYPE_TRUE) {
22         if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0')
23             v = "...";
24-
25-        xs *s1 = xs_fmt("<details><summary>%s [%s]</summary>\n", v, L("SENSITIVE CONTENT"));
26-        s = xs_str_cat(s, s1);
27-
28-        sensitive = 1;
29+        char *cw = xs_dict_get(snac->config, "cw");
30+        if (xs_is_null(cw))
31+            cw = "";
32+        if (strcmp(cw, "checked") == 0) {
33+            xs *s1 = xs_fmt("<h3>%s</h3>", v);
34+            s = xs_str_cat(s, s1);
35+        } else {
36+            xs *s1 = xs_fmt("<details><summary>%s [%s]</summary>\n", v, L("SENSITIVE CONTENT"));
37+            s = xs_str_cat(s, s1);
38+            sensitive = 1;
39+        }
40     }
41 
42 #if 0
43@@ -1379,6 +1390,12 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
44             snac.config = xs_dict_set(snac.config, "avatar", v);
45         if ((v = xs_dict_get(p_vars, "bio")) != NULL)
46             snac.config = xs_dict_set(snac.config, "bio", v);
47+        if ((v = xs_dict_get(p_vars, "cw")) != NULL &&
48+            strcmp(v, "on") == 0) {
49+            snac.config = xs_dict_set(snac.config, "cw", "checked");
50+        } else { /* if the checkbox is not set, the parameter is missing */
51+            snac.config = xs_dict_set(snac.config, "cw", "");
52+        }
53         if ((v = xs_dict_get(p_vars, "email")) != NULL)
54             snac.config = xs_dict_set(snac.config, "email", v);
55 
56@@ -1428,4 +1445,3 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
57 
58     return status;
59 }
60-
+1, -0
1@@ -226,6 +226,7 @@ int adduser(char *uid)
2     config = xs_dict_append(config, "name",      uid);
3     config = xs_dict_append(config, "avatar",    "");
4     config = xs_dict_append(config, "bio",       "");
5+    config = xs_dict_append(config, "cw",        "");
6     config = xs_dict_append(config, "published", date);
7     config = xs_dict_append(config, "passwd",    pwd_f);
8