commit da18efd
default
·
2024-04-29 08:48:48 +0000 UTC
parent f122180
More tweaks to mastoapi lists.
1 files changed,
+41,
-11
+41,
-11
1@@ -1863,22 +1863,52 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 if (xs_startswith(cmd, "/v1/lists/")) { /** list information **/
3 if (logged_in) {
4 xs *l = xs_split(cmd, "/");
5- char *op = xs_list_get(l, -1);
6- char *id = xs_list_get(l, -2);
7+ char *p = xs_list_get(l, -1);
8
9- if (op && id && xs_is_hex(id)) {
10- if (strcmp(op, "accounts") == 0) {
11- xs *actors = list_content(&snac1, id, NULL, 0);
12+ if (p) {
13+ if (strcmp(p, "accounts") == 0) {
14+ p = xs_list_get(l, -2);
15+
16+ if (p && xs_is_hex(p)) {
17+ xs *actors = list_content(&snac1, p, NULL, 0);
18+ xs *out = xs_list_new();
19+ int c = 0;
20+ char *v;
21+
22+ while (xs_list_next(actors, &v, &c)) {
23+ xs *actor = NULL;
24+
25+ if (valid_status(object_get_by_md5(v, &actor))) {
26+ xs *acct = mastoapi_account(actor);
27+ out = xs_list_append(out, acct);
28+ }
29+ }
30+
31+ *body = xs_json_dumps(out, 4);
32+ *ctype = "application/json";
33+ status = 200;
34+ }
35+ }
36+ else
37+ if (xs_is_hex(p)) {
38 xs *out = xs_list_new();
39+ xs *lol = list_maint(&snac1, NULL, 0);
40 int c = 0;
41- char *v;
42+ xs_list *v;
43+
44+ while (xs_list_next(lol, &v, &c)) {
45+ char *id = xs_list_get(v, 0);
46+
47+ if (id && strcmp(id, p) == 0) {
48+ xs *d = xs_dict_new();
49
50- while (xs_list_next(actors, &v, &c)) {
51- xs *actor = NULL;
52+ d = xs_dict_append(d, "id", p);
53+ d = xs_dict_append(d, "title", xs_list_get(v, 1));
54+ d = xs_dict_append(d, "replies_policy", "list");
55+ d = xs_dict_append(d, "exclusive", xs_stock(XSTYPE_FALSE));
56
57- if (valid_status(object_get_by_md5(v, &actor))) {
58- xs *acct = mastoapi_account(actor);
59- out = xs_list_append(out, acct);
60+ out = xs_list_append(out, d);
61+ break;
62 }
63 }
64