commit f076439

default  ·  2025-02-27 15:15:50 +0000 UTC
parent 190d1d6
Added web UI for the blocked hashtags.
1 files changed,  +61, -0
M html.c
M html.c
+61, -0
 1@@ -1514,6 +1514,38 @@ xs_html *html_top_controls(snac *user)
 2                     xs_html_attr("class", "button"),
 3                     xs_html_attr("value", L("Update hashtags")))))));
 4 
 5+    xs *blocked_hashtags_action = xs_fmt("%s/admin/blocked-hashtags", user->actor);
 6+    xs *blocked_hashtags = xs_join(xs_dict_get_def(user->config,
 7+                        "blocked_hashtags", xs_stock(XSTYPE_LIST)), "\n");
 8+
 9+    xs_html_add(top_controls,
10+        xs_html_tag("details",
11+        xs_html_tag("summary",
12+            xs_html_text(L("Blocked hashtags..."))),
13+        xs_html_tag("p",
14+            xs_html_text(L("One hashtag per line"))),
15+        xs_html_tag("div",
16+            xs_html_attr("class", "snac-blocked-hashtags"),
17+            xs_html_tag("form",
18+                xs_html_attr("autocomplete", "off"),
19+                xs_html_attr("method", "post"),
20+                xs_html_attr("action", blocked_hashtags_action),
21+                xs_html_attr("enctype", "multipart/form-data"),
22+
23+                xs_html_tag("textarea",
24+                    xs_html_attr("name", "blocked_hashtags"),
25+                    xs_html_attr("cols", "40"),
26+                    xs_html_attr("rows", "4"),
27+                    xs_html_attr("placeholder", "#cats\n#windowfriday\n#classicalmusic"),
28+                    xs_html_text(blocked_hashtags)),
29+
30+                xs_html_tag("br", NULL),
31+
32+                xs_html_sctag("input",
33+                    xs_html_attr("type", "submit"),
34+                    xs_html_attr("class", "button"),
35+                    xs_html_attr("value", L("Update hashtags")))))));
36+
37     return top_controls;
38 }
39 
40@@ -4683,6 +4715,35 @@ int html_post_handler(const xs_dict *req, const char *q_path,
41 
42         status = HTTP_STATUS_SEE_OTHER;
43     }
44+    else
45+    if (p_path && strcmp(p_path, "admin/blocked-hashtags") == 0) { /** **/
46+        const char *hashtags = xs_dict_get(p_vars, "blocked_hashtags");
47+
48+        if (xs_is_string(hashtags)) {
49+            xs *new_hashtags = xs_list_new();
50+            xs *l = xs_split(hashtags, "\n");
51+            const char *v;
52+
53+            xs_list_foreach(l, v) {
54+                xs *s1 = xs_strip_i(xs_dup(v));
55+                s1 = xs_replace_i(s1, " ", "");
56+
57+                if (*s1 == '\0')
58+                    continue;
59+
60+                xs *s2 = xs_utf8_to_lower(s1);
61+                if (*s2 != '#')
62+                    s2 = xs_str_prepend_i(s2, "#");
63+
64+                new_hashtags = xs_list_append(new_hashtags, s2);
65+            }
66+
67+            snac.config = xs_dict_set(snac.config, "blocked_hashtags", new_hashtags);
68+            user_persist(&snac, 0);
69+        }
70+
71+        status = HTTP_STATUS_SEE_OTHER;
72+    }
73 
74     if (status == HTTP_STATUS_SEE_OTHER) {
75         const char *redir = xs_dict_get(p_vars, "redir");