diff options
| author | 2025-12-26 15:15:14 -0300 | |
|---|---|---|
| committer | 2025-12-26 15:15:14 -0300 | |
| commit | f5f03f4634b534b025ea11d570bf469f9d1667d0 (patch) | |
| tree | f8b037be59d46558949dda1368322747a21f238d /mastoapi.c | |
| parent | Update pt_BR translation (diff) | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-f5f03f4634b534b025ea11d570bf469f9d1667d0.tar.gz snac2-f5f03f4634b534b025ea11d570bf469f9d1667d0.tar.xz snac2-f5f03f4634b534b025ea11d570bf469f9d1667d0.zip | |
Merge remote-tracking branch 'origin/master' into pt_BR-6
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 82 |
1 files changed, 43 insertions, 39 deletions
| @@ -1985,60 +1985,64 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1985 | } | 1985 | } |
| 1986 | else | 1986 | else |
| 1987 | if (strcmp(opt, "statuses") == 0) { /** **/ | 1987 | if (strcmp(opt, "statuses") == 0) { /** **/ |
| 1988 | /* the public list of posts of a user */ | 1988 | if (logged_in || xs_type(xs_dict_get(snac2.config, "private")) == XSTYPE_FALSE) { |
| 1989 | const char *limit_s = xs_dict_get(args, "limit"); | 1989 | /* the public list of posts of a user */ |
| 1990 | const char *o_max_id = xs_dict_get(args, "max_id"); | 1990 | const char *limit_s = xs_dict_get(args, "limit"); |
| 1991 | int limit = limit_s ? atoi(limit_s) : 20; | 1991 | const char *o_max_id = xs_dict_get(args, "max_id"); |
| 1992 | xs *max_id = o_max_id ? xs_tolower_i(xs_dup(o_max_id)) : NULL; | 1992 | int limit = limit_s ? atoi(limit_s) : 20; |
| 1993 | xs *max_id = o_max_id ? xs_tolower_i(xs_dup(o_max_id)) : NULL; | ||
| 1993 | 1994 | ||
| 1994 | srv_debug(1, xs_fmt("account statuses: max_id=%s limit=%d", max_id ? max_id : "(null)", limit)); | 1995 | srv_debug(1, xs_fmt("account statuses: max_id=%s limit=%d", max_id ? max_id : "(null)", limit)); |
| 1995 | 1996 | ||
| 1996 | xs *timeline = timeline_simple_list(&snac2, "public", 0, 256, NULL); | 1997 | xs *timeline = timeline_simple_list(&snac2, "public", 0, 256, NULL); |
| 1997 | xs_list *p = timeline; | 1998 | xs_list *p = timeline; |
| 1998 | const xs_str *v; | 1999 | const xs_str *v; |
| 1999 | xs_set seen; | 2000 | xs_set seen; |
| 2000 | int cnt = 0; | 2001 | int cnt = 0; |
| 2001 | int skip_until_max = max_id != NULL; | 2002 | int skip_until_max = max_id != NULL; |
| 2002 | 2003 | ||
| 2003 | out = xs_list_new(); | 2004 | out = xs_list_new(); |
| 2004 | xs_set_init(&seen); | 2005 | xs_set_init(&seen); |
| 2005 | 2006 | ||
| 2006 | while (xs_list_iter(&p, &v) && cnt < limit) { | 2007 | while (xs_list_iter(&p, &v) && cnt < limit) { |
| 2007 | xs *msg = NULL; | 2008 | xs *msg = NULL; |
| 2008 | 2009 | ||
| 2009 | if (valid_status(timeline_get_by_md5(&snac2, v, &msg))) { | 2010 | if (valid_status(timeline_get_by_md5(&snac2, v, &msg))) { |
| 2010 | const char *msg_id = xs_dict_get(msg, "id"); | 2011 | const char *msg_id = xs_dict_get(msg, "id"); |
| 2011 | 2012 | ||
| 2012 | /* add only posts by the author */ | 2013 | /* add only posts by the author */ |
| 2013 | if (!xs_is_null(msg_id) && | 2014 | if (!xs_is_null(msg_id) && |
| 2014 | strcmp(xs_dict_get(msg, "type"), "Note") == 0 && | 2015 | strcmp(xs_dict_get(msg, "type"), "Note") == 0 && |
| 2015 | is_msg_mine(&snac2, xs_dict_get(msg, "id")) && is_msg_public(msg)) { | 2016 | is_msg_mine(&snac2, xs_dict_get(msg, "id")) && is_msg_public(msg)) { |
| 2016 | 2017 | ||
| 2017 | /* if max_id is set, skip entries until we find it */ | 2018 | /* if max_id is set, skip entries until we find it */ |
| 2018 | if (skip_until_max) { | 2019 | if (skip_until_max) { |
| 2019 | xs *mid = mastoapi_id(msg); | 2020 | xs *mid = mastoapi_id(msg); |
| 2020 | if (strcmp(mid, max_id) == 0) { | 2021 | if (strcmp(mid, max_id) == 0) { |
| 2021 | skip_until_max = 0; | 2022 | skip_until_max = 0; |
| 2022 | srv_debug(2, xs_fmt("account statuses: found max_id, starting from next post")); | 2023 | srv_debug(2, xs_fmt("account statuses: found max_id, starting from next post")); |
| 2024 | } | ||
| 2025 | continue; | ||
| 2023 | } | 2026 | } |
| 2024 | continue; | ||
| 2025 | } | ||
| 2026 | 2027 | ||
| 2027 | /* deduplicate by message id */ | 2028 | /* deduplicate by message id */ |
| 2028 | if (xs_set_add(&seen, msg_id) == 1) { | 2029 | if (xs_set_add(&seen, msg_id) == 1) { |
| 2029 | xs *st = mastoapi_status(&snac2, msg); | 2030 | xs *st = mastoapi_status(&snac2, msg); |
| 2030 | 2031 | ||
| 2031 | if (st) { | 2032 | if (st) { |
| 2032 | out = xs_list_append(out, st); | 2033 | out = xs_list_append(out, st); |
| 2033 | cnt++; | 2034 | cnt++; |
| 2035 | } | ||
| 2034 | } | 2036 | } |
| 2035 | } | 2037 | } |
| 2036 | } | 2038 | } |
| 2037 | } | 2039 | } |
| 2038 | } | ||
| 2039 | 2040 | ||
| 2040 | srv_debug(1, xs_fmt("account statuses: returning %d posts (requested %d)", cnt, limit)); | 2041 | srv_debug(1, xs_fmt("account statuses: returning %d posts (requested %d)", cnt, limit)); |
| 2041 | xs_set_free(&seen); | 2042 | xs_set_free(&seen); |
| 2043 | } | ||
| 2044 | else | ||
| 2045 | status = HTTP_STATUS_UNAUTHORIZED; | ||
| 2042 | } | 2046 | } |
| 2043 | else | 2047 | else |
| 2044 | if (strcmp(opt, "featured_tags") == 0) { | 2048 | if (strcmp(opt, "featured_tags") == 0) { |