Kaynağa Gözat

New user option 'purge_days'.

default 3 yıl önce
ebeveyn
işleme
70c73d0336
3 değiştirilmiş dosya ile 30 ekleme ve 2 silme
  1. 14 1
      data.c
  2. 15 0
      html.c
  3. 1 1
      snac.h

+ 14 - 1
data.c

@@ -1575,11 +1575,24 @@ void purge_server(void)
 void purge_user(snac *snac)
 /* do the purge for this user */
 {
-    int priv_days, pub_days;
+    int priv_days, pub_days, user_days = 0;
+    char *v;
 
     priv_days = xs_number_get(xs_dict_get(srv_config, "timeline_purge_days"));
     pub_days  = xs_number_get(xs_dict_get(srv_config, "local_purge_days"));
 
+    if ((v = xs_dict_get(snac->config, "purge_days")) != NULL)
+        user_days = xs_number_get(v);
+
+    if (user_days) {
+        /* override admin settings only if they are lesser */
+        if (priv_days == 0 || user_days < priv_days)
+            priv_days = user_days;
+
+        if (pub_days == 0 || user_days < pub_days)
+            pub_days = user_days;
+    }
+
     _purge_subdir(snac, "hidden",  priv_days);
     _purge_subdir(snac, "private", priv_days);
 

+ 15 - 0
html.c

@@ -306,6 +306,9 @@ d_char *html_top_controls(snac *snac, d_char *s)
         "<p>%s:<br>\n"
         "<input type=\"text\" name=\"email\" value=\"%s\"></p>\n"
 
+        "<p>%s:<br>\n"
+        "<input type=\"number\" name=\"purge_days\" value=\"%s\"></p>\n"
+
         "<p>%s:<br>\n"
         "<input type=\"password\" name=\"passwd1\" value=\"\"></p>\n"
 
@@ -329,6 +332,12 @@ d_char *html_top_controls(snac *snac, d_char *s)
     if (xs_is_null(cw))
         cw = "";
 
+    const char *purge_days = xs_dict_get(snac->config, "purge_days");
+    if (!xs_is_null(purge_days) && xs_type(purge_days) == XSTYPE_NUMBER)
+        purge_days = xs_number_str(purge_days);
+    else
+        purge_days = "0";
+
     xs *s1 = xs_fmt(_tmpl,
         snac->actor,
         L("Sensitive content"),
@@ -355,6 +364,8 @@ d_char *html_top_controls(snac *snac, d_char *s)
         L("Always show sensitive content"),
         L("Email address for notifications"),
         email,
+        L("Maximum days to keep posts (0: server settings)"),
+        purge_days,
         L("Password (only to change it)"),
         L("Repeat Password"),
         L("Update user info")
@@ -1567,6 +1578,10 @@ int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
         }
         if ((v = xs_dict_get(p_vars, "email")) != NULL)
             snac.config = xs_dict_set(snac.config, "email", v);
+        if ((v = xs_dict_get(p_vars, "purge_days")) != NULL) {
+            xs *days    = xs_number_new(atof(v));
+            snac.config = xs_dict_set(snac.config, "purge_days", days);
+        }
 
         /* password change? */
         if ((p1 = xs_dict_get(p_vars, "passwd1")) != NULL &&

+ 1 - 1
snac.h

@@ -1,7 +1,7 @@
 /* snac - A simple, minimalistic ActivityPub instance */
 /* copyright (c) 2022 - 2023 grunfink / MIT license */
 
-#define VERSION "2.20"
+#define VERSION "2.21-dev"
 
 #define USER_AGENT "snac/" VERSION