diff options
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 62 |
1 files changed, 47 insertions, 15 deletions
| @@ -1500,6 +1500,44 @@ xs_str *timeline_link_header(const char *endpoint, xs_list *timeline) | |||
| 1500 | } | 1500 | } |
| 1501 | 1501 | ||
| 1502 | 1502 | ||
| 1503 | xs_list *mastoapi_account_lists(snac *user, const char *uid) | ||
| 1504 | /* returns the list of list an user is in */ | ||
| 1505 | { | ||
| 1506 | xs_list *out = xs_list_new(); | ||
| 1507 | xs *actor_md5 = NULL; | ||
| 1508 | xs *lol = list_maint(user, NULL, 0); | ||
| 1509 | |||
| 1510 | if (uid) { | ||
| 1511 | if (!xs_is_hex(uid)) | ||
| 1512 | actor_md5 = xs_md5_hex(uid, strlen(uid)); | ||
| 1513 | else | ||
| 1514 | actor_md5 = xs_dup(uid); | ||
| 1515 | } | ||
| 1516 | |||
| 1517 | const xs_list *li; | ||
| 1518 | xs_list_foreach(lol, li) { | ||
| 1519 | const char *list_id = xs_list_get(li, 0); | ||
| 1520 | const char *list_title = xs_list_get(li, 1); | ||
| 1521 | if (uid) { | ||
| 1522 | xs *users = list_content(user, list_id, NULL, 0); | ||
| 1523 | if (xs_list_in(users, actor_md5) == -1) | ||
| 1524 | continue; | ||
| 1525 | } | ||
| 1526 | |||
| 1527 | xs *d = xs_dict_new(); | ||
| 1528 | |||
| 1529 | d = xs_dict_append(d, "id", list_id); | ||
| 1530 | d = xs_dict_append(d, "title", list_title); | ||
| 1531 | d = xs_dict_append(d, "replies_policy", "list"); | ||
| 1532 | d = xs_dict_append(d, "exclusive", xs_stock(XSTYPE_FALSE)); | ||
| 1533 | |||
| 1534 | out = xs_list_append(out, d); | ||
| 1535 | } | ||
| 1536 | |||
| 1537 | return out; | ||
| 1538 | } | ||
| 1539 | |||
| 1540 | |||
| 1503 | int mastoapi_get_handler(const xs_dict *req, const char *q_path, | 1541 | int mastoapi_get_handler(const xs_dict *req, const char *q_path, |
| 1504 | char **body, int *b_size, char **ctype, xs_str **link) | 1542 | char **body, int *b_size, char **ctype, xs_str **link) |
| 1505 | { | 1543 | { |
| @@ -1723,6 +1761,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1723 | if (strcmp(opt, "followers") == 0) { | 1761 | if (strcmp(opt, "followers") == 0) { |
| 1724 | out = xs_list_new(); | 1762 | out = xs_list_new(); |
| 1725 | } | 1763 | } |
| 1764 | else | ||
| 1765 | if (strcmp(opt, "lists") == 0) { | ||
| 1766 | out = mastoapi_account_lists(&snac1, uid); | ||
| 1767 | } | ||
| 1726 | 1768 | ||
| 1727 | user_free(&snac2); | 1769 | user_free(&snac2); |
| 1728 | } | 1770 | } |
| @@ -1744,6 +1786,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1744 | /* implement empty response so apps like Tokodon don't show an error */ | 1786 | /* implement empty response so apps like Tokodon don't show an error */ |
| 1745 | out = xs_list_new(); | 1787 | out = xs_list_new(); |
| 1746 | } | 1788 | } |
| 1789 | else | ||
| 1790 | if (strcmp(opt, "lists") == 0) { | ||
| 1791 | out = mastoapi_account_lists(&snac1, uid); | ||
| 1792 | } | ||
| 1747 | } | 1793 | } |
| 1748 | } | 1794 | } |
| 1749 | 1795 | ||
| @@ -1975,21 +2021,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1975 | else | 2021 | else |
| 1976 | if (strcmp(cmd, "/v1/lists") == 0) { /** list of lists **/ | 2022 | if (strcmp(cmd, "/v1/lists") == 0) { /** list of lists **/ |
| 1977 | if (logged_in) { | 2023 | if (logged_in) { |
| 1978 | xs *lol = list_maint(&snac1, NULL, 0); | 2024 | xs *l = mastoapi_account_lists(&snac1, NULL); |
| 1979 | xs *l = xs_list_new(); | ||
| 1980 | int c = 0; | ||
| 1981 | const xs_list *li; | ||
| 1982 | |||
| 1983 | while (xs_list_next(lol, &li, &c)) { | ||
| 1984 | xs *d = xs_dict_new(); | ||
| 1985 | |||
| 1986 | d = xs_dict_append(d, "id", xs_list_get(li, 0)); | ||
| 1987 | d = xs_dict_append(d, "title", xs_list_get(li, 1)); | ||
| 1988 | d = xs_dict_append(d, "replies_policy", "list"); | ||
| 1989 | d = xs_dict_append(d, "exclusive", xs_stock(XSTYPE_FALSE)); | ||
| 1990 | |||
| 1991 | l = xs_list_append(l, d); | ||
| 1992 | } | ||
| 1993 | 2025 | ||
| 1994 | *body = xs_json_dumps(l, 4); | 2026 | *body = xs_json_dumps(l, 4); |
| 1995 | *ctype = "application/json"; | 2027 | *ctype = "application/json"; |