commit c582403

fruye  ·  2025-12-22 19:52:14 +0000 UTC
parent 4eb1052
mastoapi: fixed status visibility error.
1 files changed,  +43, -39
+43, -39
  1@@ -1985,60 +1985,64 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
  2                 }
  3                 else
  4                 if (strcmp(opt, "statuses") == 0) { /** **/
  5-                    /* the public list of posts of a user */
  6-                    const char *limit_s  = xs_dict_get(args, "limit");
  7-                    const char *o_max_id = xs_dict_get(args, "max_id");
  8-                    int limit = limit_s ? atoi(limit_s) : 20;
  9-                    xs *max_id = o_max_id ? xs_tolower_i(xs_dup(o_max_id)) : NULL;
 10+                    if (logged_in || xs_type(xs_dict_get(snac2.config, "private")) == XSTYPE_FALSE) {
 11+                        /* the public list of posts of a user */
 12+                        const char *limit_s  = xs_dict_get(args, "limit");
 13+                        const char *o_max_id = xs_dict_get(args, "max_id");
 14+                        int limit = limit_s ? atoi(limit_s) : 20;
 15+                        xs *max_id = o_max_id ? xs_tolower_i(xs_dup(o_max_id)) : NULL;
 16 
 17-                    srv_debug(1, xs_fmt("account statuses: max_id=%s limit=%d", max_id ? max_id : "(null)", limit));
 18+                        srv_debug(1, xs_fmt("account statuses: max_id=%s limit=%d", max_id ? max_id : "(null)", limit));
 19 
 20-                    xs *timeline = timeline_simple_list(&snac2, "public", 0, 256, NULL);
 21-                    xs_list *p   = timeline;
 22-                    const xs_str *v;
 23-                    xs_set seen;
 24-                    int cnt = 0;
 25-                    int skip_until_max = max_id != NULL;
 26+                        xs *timeline = timeline_simple_list(&snac2, "public", 0, 256, NULL);
 27+                        xs_list *p   = timeline;
 28+                        const xs_str *v;
 29+                        xs_set seen;
 30+                        int cnt = 0;
 31+                        int skip_until_max = max_id != NULL;
 32 
 33-                    out = xs_list_new();
 34-                    xs_set_init(&seen);
 35+                        out = xs_list_new();
 36+                        xs_set_init(&seen);
 37 
 38-                    while (xs_list_iter(&p, &v) && cnt < limit) {
 39-                        xs *msg = NULL;
 40+                        while (xs_list_iter(&p, &v) && cnt < limit) {
 41+                            xs *msg = NULL;
 42 
 43-                        if (valid_status(timeline_get_by_md5(&snac2, v, &msg))) {
 44-                            const char *msg_id = xs_dict_get(msg, "id");
 45+                            if (valid_status(timeline_get_by_md5(&snac2, v, &msg))) {
 46+                                const char *msg_id = xs_dict_get(msg, "id");
 47 
 48-                            /* add only posts by the author */
 49-                            if (!xs_is_null(msg_id) &&
 50-                                strcmp(xs_dict_get(msg, "type"), "Note") == 0 &&
 51-                                is_msg_mine(&snac2, xs_dict_get(msg, "id")) && is_msg_public(msg)) {
 52+                                /* add only posts by the author */
 53+                                if (!xs_is_null(msg_id) &&
 54+                                    strcmp(xs_dict_get(msg, "type"), "Note") == 0 &&
 55+                                    is_msg_mine(&snac2, xs_dict_get(msg, "id")) && is_msg_public(msg)) {
 56 
 57-                                /* if max_id is set, skip entries until we find it */
 58-                                if (skip_until_max) {
 59-                                    xs *mid = mastoapi_id(msg);
 60-                                    if (strcmp(mid, max_id) == 0) {
 61-                                        skip_until_max = 0;
 62-                                        srv_debug(2, xs_fmt("account statuses: found max_id, starting from next post"));
 63+                                    /* if max_id is set, skip entries until we find it */
 64+                                    if (skip_until_max) {
 65+                                        xs *mid = mastoapi_id(msg);
 66+                                        if (strcmp(mid, max_id) == 0) {
 67+                                            skip_until_max = 0;
 68+                                            srv_debug(2, xs_fmt("account statuses: found max_id, starting from next post"));
 69+                                        }
 70+                                        continue;
 71                                     }
 72-                                    continue;
 73-                                }
 74 
 75-                                /* deduplicate by message id */
 76-                                if (xs_set_add(&seen, msg_id) == 1) {
 77-                                    xs *st = mastoapi_status(&snac2, msg);
 78+                                    /* deduplicate by message id */
 79+                                    if (xs_set_add(&seen, msg_id) == 1) {
 80+                                        xs *st = mastoapi_status(&snac2, msg);
 81 
 82-                                    if (st) {
 83-                                        out = xs_list_append(out, st);
 84-                                        cnt++;
 85+                                        if (st) {
 86+                                            out = xs_list_append(out, st);
 87+                                            cnt++;
 88+                                        }
 89                                     }
 90                                 }
 91                             }
 92                         }
 93-                    }
 94 
 95-                    srv_debug(1, xs_fmt("account statuses: returning %d posts (requested %d)", cnt, limit));
 96-                    xs_set_free(&seen);
 97+                        srv_debug(1, xs_fmt("account statuses: returning %d posts (requested %d)", cnt, limit));
 98+                        xs_set_free(&seen);
 99+                    }
100+                    else
101+                        status = HTTP_STATUS_UNAUTHORIZED;
102                 }
103                 else
104                 if (strcmp(opt, "featured_tags") == 0) {