commit 8524ace

default  ·  2023-10-07 22:06:37 +0000 UTC
parent 8676d87
Hide posts from the public web for accounts with 'private' == true.
3 files changed,  +53, -0
M html.c
M html.c
+31, -0
 1@@ -1567,6 +1567,25 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int
 2         if (!valid_status(status))
 3             continue;
 4 
 5+        /* if it's an instance page, discard private users */
 6+        if (user == NULL) {
 7+            const char *atto = xs_dict_get(msg, "attributedTo");
 8+            xs *l = xs_split(atto, "/");
 9+            const char *uid = xs_list_get(l, -1);
10+            snac user;
11+            int skip = 1;
12+
13+            if (uid && user_open(&user, uid)) {
14+                if (xs_type(xs_dict_get(user.config, "private")) != XSTYPE_TRUE)
15+                    skip = 0;
16+
17+                user_free(&user);
18+            }
19+
20+            if (skip)
21+                continue;
22+        }
23+
24         s = html_entry(user, s, msg, local, 0, v, user ? 0 : 1);
25     }
26 
27@@ -1940,6 +1959,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
28         show = atoi(v), cache = 0, save = 0;
29 
30     if (p_path == NULL) { /** public timeline **/
31+        if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE)
32+            return 403;
33+
34         xs *h = xs_str_localtime(0, "%Y-%m.html");
35 
36         if (cache && history_mtime(&snac, h) > timeline_mtime(&snac)) {
37@@ -2022,6 +2044,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
38     }
39     else
40     if (xs_startswith(p_path, "p/")) { /** a timeline with just one entry **/
41+        if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE)
42+            return 403;
43+
44         xs *id  = xs_fmt("%s/%s", snac.actor, p_path);
45         xs *msg = NULL;
46 
47@@ -2054,6 +2079,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
48     }
49     else
50     if (xs_startswith(p_path, "h/")) { /** an entry from the history **/
51+        if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE)
52+            return 403;
53+
54         xs *l    = xs_split(p_path, "/");
55         char *id = xs_list_get(l, 1);
56 
57@@ -2070,6 +2098,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
58     }
59     else
60     if (strcmp(p_path, ".rss") == 0) { /** public timeline in RSS format **/
61+        if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE)
62+            return 403;
63+
64         xs_str *rss;
65         xs *elems = timeline_simple_list(&snac, "public", 0, 20);
66         xs *bio   = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL);
+3, -0
 1@@ -284,6 +284,9 @@ void httpd_connection(FILE *f)
 2         status = 404;
 3     }
 4 
 5+    if (status == 403)
 6+        body = xs_str_new("<h1>403 Forbidden</h1>");
 7+
 8     if (status == 404)
 9         body = xs_str_new("<h1>404 Not Found</h1>");
10 
+19, -0
 1@@ -1377,6 +1377,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2             if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0)
 3                 continue;
 4 
 5+            /* discard private users */
 6+            {
 7+                const char *atto = xs_dict_get(msg, "attributedTo");
 8+                xs *l = xs_split(atto, "/");
 9+                const char *uid = xs_list_get(l, -1);
10+                snac p_user;
11+                int skip = 1;
12+
13+                if (uid && user_open(&p_user, uid)) {
14+                    if (xs_type(xs_dict_get(p_user.config, "private")) != XSTYPE_TRUE)
15+                        skip = 0;
16+
17+                    user_free(&p_user);
18+                }
19+
20+                if (skip)
21+                    continue;
22+            }
23+
24             /* convert the Note into a Mastodon status */
25             xs *st = mastoapi_status(user, msg);
26