commit 0930ce7

default  ·  2024-02-10 08:08:09 +0000 UTC
parent 151c5aa
New function is_msg_from_private_user().
4 files changed,  +35, -36
M html.c
M snac.h
+24, -0
 1@@ -593,6 +593,30 @@ int is_msg_public(const xs_dict *msg)
 2 }
 3 
 4 
 5+int is_msg_from_private_user(const xs_dict *msg)
 6+/* checks if a message is from a local, private user */
 7+{
 8+    int ret = 0;
 9+
10+    /* is this message from a local user? */
11+    if (xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) {
12+        const char *atto = get_atto(msg);
13+        xs *l = xs_split(atto, "/");
14+        const char *uid = xs_list_get(l, -1);
15+        snac user;
16+
17+        if (uid && user_open(&user, uid)) {
18+            if (xs_type(xs_dict_get(user.config, "private")) == XSTYPE_TRUE)
19+                ret = 1;
20+
21+            user_free(&user);
22+        }
23+    }
24+
25+    return ret;
26+}
27+
28+
29 int is_msg_for_me(snac *snac, const xs_dict *c_msg)
30 /* checks if this message is for me */
31 {
M html.c
+3, -18
 1@@ -1911,24 +1911,9 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local,
 2         if (!valid_status(status))
 3             continue;
 4 
 5-        /* if it's an instance page, discard private users */
 6-        if (user == NULL && xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) {
 7-            const char *atto = get_atto(msg);
 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+        /* if it's an instance page, discard messages from private users */
24+        if (user == NULL && is_msg_from_private_user(msg))
25+            continue;
26 
27         xs_html *entry = html_entry(user, msg, local, 0, v, user ? 0 : 1);
28 
+7, -18
 1@@ -1500,24 +1500,9 @@ 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 = get_atto(msg);
 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+            /* discard messages from private users */
24+            if (is_msg_from_private_user(msg))
25+                continue;
26 
27             /* convert the Note into a Mastodon status */
28             xs *st = mastoapi_status(user, msg);
29@@ -1564,6 +1549,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
30             if (!is_msg_public(msg))
31                 continue;
32 
33+            /* discard messages from private users */
34+            if (is_msg_from_private_user(msg))
35+                continue;
36+
37             /* convert the Note into a Mastodon status */
38             xs *st = mastoapi_status(NULL, msg);
39 
M snac.h
+1, -0
1@@ -277,6 +277,7 @@ xs_str *get_actor_inbox(const char *actor);
2 int send_to_actor(snac *snac, const char *actor, const xs_dict *msg,
3                   xs_val **payload, int *p_size, int timeout);
4 int is_msg_public(const xs_dict *msg);
5+int is_msg_from_private_user(const xs_dict *msg);
6 int is_msg_for_me(snac *snac, const xs_dict *msg);
7 
8 int process_user_queue(snac *snac);