commit 70c73d0

default  ·  2023-02-05 18:09:22 +0000 UTC
parent 143c735
New user option 'purge_days'.
3 files changed,  +30, -2
M data.c
M html.c
M snac.h
M data.c
+14, -1
 1@@ -1575,11 +1575,24 @@ void purge_server(void)
 2 void purge_user(snac *snac)
 3 /* do the purge for this user */
 4 {
 5-    int priv_days, pub_days;
 6+    int priv_days, pub_days, user_days = 0;
 7+    char *v;
 8 
 9     priv_days = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
10     pub_days  = xs_number_get(xs_dict_get(srv_config, "local_purge_days"));
11 
12+    if ((v = xs_dict_get(snac->config, "purge_days")) != NULL)
13+        user_days = xs_number_get(v);
14+
15+    if (user_days) {
16+        /* override admin settings only if they are lesser */
17+        if (priv_days == 0 || user_days < priv_days)
18+            priv_days = user_days;
19+
20+        if (pub_days == 0 || user_days < pub_days)
21+            pub_days = user_days;
22+    }
23+
24     _purge_subdir(snac, "hidden",  priv_days);
25     _purge_subdir(snac, "private", priv_days);
26 
M html.c
+15, -0
 1@@ -306,6 +306,9 @@ d_char *html_top_controls(snac *snac, d_char *s)
 2         "<p>%s:<br>\n"
 3         "<input type=\"text\" name=\"email\" value=\"%s\"></p>\n"
 4 
 5+        "<p>%s:<br>\n"
 6+        "<input type=\"number\" name=\"purge_days\" value=\"%s\"></p>\n"
 7+
 8         "<p>%s:<br>\n"
 9         "<input type=\"password\" name=\"passwd1\" value=\"\"></p>\n"
10 
11@@ -329,6 +332,12 @@ d_char *html_top_controls(snac *snac, d_char *s)
12     if (xs_is_null(cw))
13         cw = "";
14 
15+    const char *purge_days = xs_dict_get(snac->config, "purge_days");
16+    if (!xs_is_null(purge_days) && xs_type(purge_days) == XSTYPE_NUMBER)
17+        purge_days = xs_number_str(purge_days);
18+    else
19+        purge_days = "0";
20+
21     xs *s1 = xs_fmt(_tmpl,
22         snac->actor,
23         L("Sensitive content"),
24@@ -355,6 +364,8 @@ d_char *html_top_controls(snac *snac, d_char *s)
25         L("Always show sensitive content"),
26         L("Email address for notifications"),
27         email,
28+        L("Maximum days to keep posts (0: server settings)"),
29+        purge_days,
30         L("Password (only to change it)"),
31         L("Repeat Password"),
32         L("Update user info")
33@@ -1567,6 +1578,10 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
34         }
35         if ((v = xs_dict_get(p_vars, "email")) != NULL)
36             snac.config = xs_dict_set(snac.config, "email", v);
37+        if ((v = xs_dict_get(p_vars, "purge_days")) != NULL) {
38+            xs *days    = xs_number_new(atof(v));
39+            snac.config = xs_dict_set(snac.config, "purge_days", days);
40+        }
41 
42         /* password change? */
43         if ((p1 = xs_dict_get(p_vars, "passwd1")) != NULL &&
M snac.h
+1, -1
1@@ -1,7 +1,7 @@
2 /* snac - A simple, minimalistic ActivityPub instance */
3 /* copyright (c) 2022 - 2023 grunfink / MIT license */
4 
5-#define VERSION "2.20"
6+#define VERSION "2.21-dev"
7 
8 #define USER_AGENT "snac/" VERSION
9