commit 72839e5

default  ·  2023-08-12 10:10:42 +0000 UTC
parent cac1c6f
mastoapi: fixed /api/timelines/public to not need a bearer token.
1 files changed,  +13, -12
+13, -12
 1@@ -622,7 +622,8 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
 2     poll = xs_dict_append(poll, "votes_count", vc);
 3 
 4     poll = xs_dict_append(poll, "voted",
 5-            was_question_voted(snac, xs_dict_get(msg, "id")) ? xs_stock_true : xs_stock_false);
 6+            (snac && was_question_voted(snac, xs_dict_get(msg, "id"))) ?
 7+                xs_stock_true : xs_stock_false);
 8 
 9     return poll;
10 }
11@@ -725,7 +726,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
12                 const char *href = xs_dict_get(v, "href");
13 
14                 if (!xs_is_null(name) && !xs_is_null(href) &&
15-                    strcmp(href, snac->actor) != 0) {
16+                    (snac == NULL || strcmp(href, snac->actor) != 0)) {
17                     xs *nm = xs_strip_chars_i(xs_dup(name), "@");
18 
19                     xs *id = xs_fmt("%d", n++);
20@@ -786,7 +787,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
21 
22     st = xs_dict_append(st, "favourites_count", ixc);
23     st = xs_dict_append(st, "favourited",
24-        xs_list_in(idx, snac->md5) != -1 ? xs_stock_true : xs_stock_false);
25+        (snac && xs_list_in(idx, snac->md5) != -1) ? xs_stock_true : xs_stock_false);
26 
27     xs_free(idx);
28     xs_free(ixc);
29@@ -795,7 +796,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
30 
31     st = xs_dict_append(st, "reblogs_count", ixc);
32     st = xs_dict_append(st, "reblogged",
33-        xs_list_in(idx, snac->md5) != -1 ? xs_stock_true : xs_stock_false);
34+        (snac && xs_list_in(idx, snac->md5) != -1) ? xs_stock_true : xs_stock_false);
35 
36     xs_free(idx);
37     xs_free(ixc);
38@@ -849,7 +850,8 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
39 
40     st = xs_dict_append(st, "bookmarked", xs_stock_false);
41 
42-    st = xs_dict_append(st, "pinned", is_pinned(snac, id) ? xs_stock_true : xs_stock_false);
43+    st = xs_dict_append(st, "pinned",
44+        (snac && is_pinned(snac, id)) ? xs_stock_true : xs_stock_false);
45 
46     return st;
47 }
48@@ -1237,11 +1239,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
49     if (strcmp(cmd, "/v1/timelines/public") == 0) { /** **/
50         /* the instance public timeline (public timelines for all users) */
51 
52-        /* NOTE: this api call needs no authorization; but,
53-           I need a logged-in user in mastoapi_status() for
54-           is_msg_public() and the liked/boosted flags,
55-           so it will silently fail for pure public access */
56-
57         const char *limit_s = xs_dict_get(args, "limit");
58         int limit = 0;
59         int cnt   = 0;
60@@ -1257,7 +1254,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
61         xs_list *p   = timeline;
62         xs_str *md5;
63 
64-        while (logged_in && xs_list_iter(&p, &md5) && cnt < limit) {
65+        snac *user = NULL;
66+        if (logged_in)
67+            user = &snac1;
68+
69+        while (xs_list_iter(&p, &md5) && cnt < limit) {
70             xs *msg = NULL;
71 
72             /* get the entry */
73@@ -1270,7 +1271,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
74                 continue;
75 
76             /* convert the Note into a Mastodon status */
77-            xs *st = mastoapi_status(&snac1, msg);
78+            xs *st = mastoapi_status(user, msg);
79 
80             if (st != NULL) {
81                 out = xs_list_append(out, st);