diff options
| author | 2023-08-12 12:10:42 +0200 | |
|---|---|---|
| committer | 2023-08-12 12:10:42 +0200 | |
| commit | 72839e59a03c2769a3aae1492e3ffbf68377ab20 (patch) | |
| tree | d8e76b46d631f2655dcadfd6a806bef6877c4a45 | |
| parent | Rewritten actor_get() to not depend on a user. (diff) | |
| download | snac2-72839e59a03c2769a3aae1492e3ffbf68377ab20.tar.gz snac2-72839e59a03c2769a3aae1492e3ffbf68377ab20.tar.xz snac2-72839e59a03c2769a3aae1492e3ffbf68377ab20.zip | |
mastoapi: fixed /api/timelines/public to not need a bearer token.
| -rw-r--r-- | mastoapi.c | 25 |
1 files changed, 13 insertions, 12 deletions
| @@ -622,7 +622,8 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg) | |||
| 622 | poll = xs_dict_append(poll, "votes_count", vc); | 622 | poll = xs_dict_append(poll, "votes_count", vc); |
| 623 | 623 | ||
| 624 | poll = xs_dict_append(poll, "voted", | 624 | poll = xs_dict_append(poll, "voted", |
| 625 | was_question_voted(snac, xs_dict_get(msg, "id")) ? xs_stock_true : xs_stock_false); | 625 | (snac && was_question_voted(snac, xs_dict_get(msg, "id"))) ? |
| 626 | xs_stock_true : xs_stock_false); | ||
| 626 | 627 | ||
| 627 | return poll; | 628 | return poll; |
| 628 | } | 629 | } |
| @@ -725,7 +726,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 725 | const char *href = xs_dict_get(v, "href"); | 726 | const char *href = xs_dict_get(v, "href"); |
| 726 | 727 | ||
| 727 | if (!xs_is_null(name) && !xs_is_null(href) && | 728 | if (!xs_is_null(name) && !xs_is_null(href) && |
| 728 | strcmp(href, snac->actor) != 0) { | 729 | (snac == NULL || strcmp(href, snac->actor) != 0)) { |
| 729 | xs *nm = xs_strip_chars_i(xs_dup(name), "@"); | 730 | xs *nm = xs_strip_chars_i(xs_dup(name), "@"); |
| 730 | 731 | ||
| 731 | xs *id = xs_fmt("%d", n++); | 732 | xs *id = xs_fmt("%d", n++); |
| @@ -786,7 +787,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 786 | 787 | ||
| 787 | st = xs_dict_append(st, "favourites_count", ixc); | 788 | st = xs_dict_append(st, "favourites_count", ixc); |
| 788 | st = xs_dict_append(st, "favourited", | 789 | st = xs_dict_append(st, "favourited", |
| 789 | xs_list_in(idx, snac->md5) != -1 ? xs_stock_true : xs_stock_false); | 790 | (snac && xs_list_in(idx, snac->md5) != -1) ? xs_stock_true : xs_stock_false); |
| 790 | 791 | ||
| 791 | xs_free(idx); | 792 | xs_free(idx); |
| 792 | xs_free(ixc); | 793 | xs_free(ixc); |
| @@ -795,7 +796,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 795 | 796 | ||
| 796 | st = xs_dict_append(st, "reblogs_count", ixc); | 797 | st = xs_dict_append(st, "reblogs_count", ixc); |
| 797 | st = xs_dict_append(st, "reblogged", | 798 | st = xs_dict_append(st, "reblogged", |
| 798 | xs_list_in(idx, snac->md5) != -1 ? xs_stock_true : xs_stock_false); | 799 | (snac && xs_list_in(idx, snac->md5) != -1) ? xs_stock_true : xs_stock_false); |
| 799 | 800 | ||
| 800 | xs_free(idx); | 801 | xs_free(idx); |
| 801 | xs_free(ixc); | 802 | xs_free(ixc); |
| @@ -849,7 +850,8 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 849 | 850 | ||
| 850 | st = xs_dict_append(st, "bookmarked", xs_stock_false); | 851 | st = xs_dict_append(st, "bookmarked", xs_stock_false); |
| 851 | 852 | ||
| 852 | st = xs_dict_append(st, "pinned", is_pinned(snac, id) ? xs_stock_true : xs_stock_false); | 853 | st = xs_dict_append(st, "pinned", |
| 854 | (snac && is_pinned(snac, id)) ? xs_stock_true : xs_stock_false); | ||
| 853 | 855 | ||
| 854 | return st; | 856 | return st; |
| 855 | } | 857 | } |
| @@ -1237,11 +1239,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1237 | if (strcmp(cmd, "/v1/timelines/public") == 0) { /** **/ | 1239 | if (strcmp(cmd, "/v1/timelines/public") == 0) { /** **/ |
| 1238 | /* the instance public timeline (public timelines for all users) */ | 1240 | /* the instance public timeline (public timelines for all users) */ |
| 1239 | 1241 | ||
| 1240 | /* NOTE: this api call needs no authorization; but, | ||
| 1241 | I need a logged-in user in mastoapi_status() for | ||
| 1242 | is_msg_public() and the liked/boosted flags, | ||
| 1243 | so it will silently fail for pure public access */ | ||
| 1244 | |||
| 1245 | const char *limit_s = xs_dict_get(args, "limit"); | 1242 | const char *limit_s = xs_dict_get(args, "limit"); |
| 1246 | int limit = 0; | 1243 | int limit = 0; |
| 1247 | int cnt = 0; | 1244 | int cnt = 0; |
| @@ -1257,7 +1254,11 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1257 | xs_list *p = timeline; | 1254 | xs_list *p = timeline; |
| 1258 | xs_str *md5; | 1255 | xs_str *md5; |
| 1259 | 1256 | ||
| 1260 | while (logged_in && xs_list_iter(&p, &md5) && cnt < limit) { | 1257 | snac *user = NULL; |
| 1258 | if (logged_in) | ||
| 1259 | user = &snac1; | ||
| 1260 | |||
| 1261 | while (xs_list_iter(&p, &md5) && cnt < limit) { | ||
| 1261 | xs *msg = NULL; | 1262 | xs *msg = NULL; |
| 1262 | 1263 | ||
| 1263 | /* get the entry */ | 1264 | /* get the entry */ |
| @@ -1270,7 +1271,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1270 | continue; | 1271 | continue; |
| 1271 | 1272 | ||
| 1272 | /* convert the Note into a Mastodon status */ | 1273 | /* convert the Note into a Mastodon status */ |
| 1273 | xs *st = mastoapi_status(&snac1, msg); | 1274 | xs *st = mastoapi_status(user, msg); |
| 1274 | 1275 | ||
| 1275 | if (st != NULL) { | 1276 | if (st != NULL) { |
| 1276 | out = xs_list_append(out, st); | 1277 | out = xs_list_append(out, st); |