commit 61d8b46

default  ·  2024-08-09 15:17:27 +0000 UTC
parent 339dc1a
More mastoapi_timeline() tweaks.
1 files changed,  +35, -18
+35, -18
 1@@ -1261,7 +1261,7 @@ void credentials_get(char **body, char **ctype, int *status, snac snac)
 2 }
 3 
 4 
 5-xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char *index_fn)
 6+xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn)
 7 {
 8     xs_list *out = xs_list_new();
 9     FILE *f;
10@@ -1269,7 +1269,7 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char
11 
12     if (dbglevel) {
13         xs *js = xs_json_dumps(args, 0);
14-        srv_log(xs_fmt("mastoapi_timeline args: %s", js));
15+        srv_debug(1, xs_fmt("mastoapi_timeline args: %s", js));
16     }
17 
18     if ((f = fopen(index_fn, "r")) == NULL)
19@@ -1288,7 +1288,7 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char
20     if (limit == 0)
21         limit = 20;
22 
23-    if (index_desc_first(f, md5, skip)) {
24+    if (index_desc_first(f, md5, 0)) {
25         do {
26             xs *msg = NULL;
27 
28@@ -1314,8 +1314,14 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char
29             }
30 
31             /* get the entry */
32-            if (!valid_status(timeline_get_by_md5(user, md5, &msg)))
33-                continue;
34+            if (user) {
35+                if (!valid_status(timeline_get_by_md5(user, md5, &msg)))
36+                    continue;
37+            }
38+            else {
39+                if (!valid_status(object_get_by_md5(md5, &msg)))
40+                    continue;
41+            }
42 
43             /* discard non-Notes */
44             const char *id   = xs_dict_get(msg, "id");
45@@ -1333,22 +1339,33 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, int skip, const char
46             if (from == NULL)
47                 continue;
48 
49-            /* is this message from a person we don't follow? */
50-            if (strcmp(from, user->actor) && !following_check(user, from)) {
51-                /* discard if it was not boosted */
52-                xs *idx = object_announces(id);
53+            if (user) {
54+                /* is this message from a person we don't follow? */
55+                if (strcmp(from, user->actor) && !following_check(user, from)) {
56+                    /* discard if it was not boosted */
57+                    xs *idx = object_announces(id);
58+
59+                    if (xs_list_len(idx) == 0)
60+                        continue;
61+                }
62+
63+                /* discard notes from muted morons */
64+                if (is_muted(user, from))
65+                    continue;
66 
67-                if (xs_list_len(idx) == 0)
68+                /* discard hidden notes */
69+                if (is_hidden(user, id))
70                     continue;
71             }
72+            else {
73+                /* skip non-public messages */
74+                if (!is_msg_public(msg))
75+                    continue;
76 
77-            /* discard notes from muted morons */
78-            if (is_muted(user, from))
79-                continue;
80-
81-            /* discard hidden notes */
82-            if (is_hidden(user, id))
83-                continue;
84+                /* discard messages from private users */
85+                if (is_msg_from_private_user(msg))
86+                    continue;
87+            }
88 
89             /* if it has a name and it's not a Page or a Video,
90                it's a poll vote, so discard it */
91@@ -1632,7 +1649,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
92         /* the private timeline */
93         if (logged_in) {
94             xs *ifn = user_index_fn(&snac1, "private");
95-            xs *out = mastoapi_timeline(&snac1, args, 0, ifn);
96+            xs *out = mastoapi_timeline(&snac1, args, ifn);
97 
98             *body  = xs_json_dumps(out, 4);
99             *ctype = "application/json";