diff options
author | default <nobody@localhost> | 2024-04-29 07:43:01 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2024-04-29 07:43:01 +0200 |
commit | 8275a5f4d8764ebc9f9f82a4db377bacfa9fbc75 (patch) | |
tree | 7d896846e16d6324d16e061a2bc08cfc0183efb0 /mastoapi.c | |
parent | a297b55dac6fac41136badf4b7af9c7a4f28a66f (diff) |
Start of list support.
Diffstat (limited to 'mastoapi.c')
-rw-r--r-- | mastoapi.c | 47 |
1 files changed, 44 insertions, 3 deletions
@@ -1767,9 +1767,27 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, else if (strcmp(cmd, "/v1/lists") == 0) { /** **/ /* snac does not support lists */ - *body = xs_dup("[]"); - *ctype = "application/json"; - status = 200; + if (logged_in) { + xs *lol = list_maint(&snac1, NULL, 0); + xs *l = xs_list_new(); + int c = 0; + xs_list *li; + + while (xs_list_next(lol, &li, &c)) { + xs *d = xs_dict_new(); + + d = xs_dict_append(d, "id", xs_list_get(li, 0)); + d = xs_dict_append(d, "title", xs_list_get(li, 1)); + d = xs_dict_append(d, "replies_policy", "list"); + d = xs_dict_append(d, "exclusive", xs_stock(XSTYPE_FALSE)); + + l = xs_list_append(l, d); + } + + *body = xs_json_dumps(l, 4); + *ctype = "application/json"; + status = 200; + } } else if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ @@ -2631,6 +2649,29 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, else status = 401; } + else + if (strcmp(cmd, "/v1/lists") == 0) { + if (logged_in) { + const char *title = xs_dict_get(args, "title"); + + if (xs_type(title) == XSTYPE_STRING) { + /* add the list */ + list_maint(&snac, title, 1); + + xs *out = xs_dict_new(); + + out = xs_dict_append(out, "title", title); + out = xs_dict_append(out, "replies_policy", xs_dict_get_def(args, "replies_policy", "list")); + out = xs_dict_append(out, "exclusive", xs_stock(XSTYPE_FALSE)); + + *body = xs_json_dumps(out, 4); + *ctype = "application/json"; + status = 200; + } + else + status = 422; + } + } /* user cleanup */ if (logged_in) |