commit 1c8ff95

grunfink  ·  2022-12-04 10:39:32 +0000 UTC
parents 7e07b01, a3fa7db
Merge pull request 'Add an option to always show sensitive content' (#9) from kensanata/snac2:optional-cw into master

Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/9
2 files changed,  +17, -4
M html.c
M html.c
+16, -4
 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,10 +618,12 @@ 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+        /* only show it when not in the public timeline and the config setting is "open" */
27+        char *cw = xs_dict_get(snac->config, "cw");
28+        if (xs_is_null(cw) || local)
29+            cw = "";
30+        xs *s1 = xs_fmt("<details %s><summary>%s [%s]</summary>\n", cw, v, L("SENSITIVE CONTENT"));
31         s = xs_str_cat(s, s1);
32-
33         sensitive = 1;
34     }
35 
36@@ -1379,6 +1386,12 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
37             snac.config = xs_dict_set(snac.config, "avatar", v);
38         if ((v = xs_dict_get(p_vars, "bio")) != NULL)
39             snac.config = xs_dict_set(snac.config, "bio", v);
40+        if ((v = xs_dict_get(p_vars, "cw")) != NULL &&
41+            strcmp(v, "on") == 0) {
42+            snac.config = xs_dict_set(snac.config, "cw", "open");
43+        } else { /* if the checkbox is not set, the parameter is missing */
44+            snac.config = xs_dict_set(snac.config, "cw", "");
45+        }
46         if ((v = xs_dict_get(p_vars, "email")) != NULL)
47             snac.config = xs_dict_set(snac.config, "email", v);
48 
49@@ -1428,4 +1441,3 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
50 
51     return status;
52 }
53-
+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