diff options
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 67 |
1 files changed, 51 insertions, 16 deletions
| @@ -1223,7 +1223,10 @@ void credentials_get(char **body, char **ctype, int *status, snac snac) | |||
| 1223 | acct = xs_dict_append(acct, "last_status_at", xs_dict_get(snac.config, "published")); | 1223 | acct = xs_dict_append(acct, "last_status_at", xs_dict_get(snac.config, "published")); |
| 1224 | acct = xs_dict_append(acct, "note", xs_dict_get(snac.config, "bio")); | 1224 | acct = xs_dict_append(acct, "note", xs_dict_get(snac.config, "bio")); |
| 1225 | acct = xs_dict_append(acct, "url", snac.actor); | 1225 | acct = xs_dict_append(acct, "url", snac.actor); |
| 1226 | acct = xs_dict_append(acct, "locked", xs_stock(XSTYPE_FALSE)); | 1226 | |
| 1227 | acct = xs_dict_append(acct, "locked", | ||
| 1228 | xs_stock(xs_is_true(xs_dict_get(snac.config, "approve_followers")) ? XSTYPE_TRUE : XSTYPE_FALSE)); | ||
| 1229 | |||
| 1227 | acct = xs_dict_append(acct, "bot", xs_stock(xs_is_true(bot) ? XSTYPE_TRUE : XSTYPE_FALSE)); | 1230 | acct = xs_dict_append(acct, "bot", xs_stock(xs_is_true(bot) ? XSTYPE_TRUE : XSTYPE_FALSE)); |
| 1228 | acct = xs_dict_append(acct, "emojis", xs_stock(XSTYPE_LIST)); | 1231 | acct = xs_dict_append(acct, "emojis", xs_stock(XSTYPE_LIST)); |
| 1229 | 1232 | ||
| @@ -1500,6 +1503,44 @@ xs_str *timeline_link_header(const char *endpoint, xs_list *timeline) | |||
| 1500 | } | 1503 | } |
| 1501 | 1504 | ||
| 1502 | 1505 | ||
| 1506 | xs_list *mastoapi_account_lists(snac *user, const char *uid) | ||
| 1507 | /* returns the list of list an user is in */ | ||
| 1508 | { | ||
| 1509 | xs_list *out = xs_list_new(); | ||
| 1510 | xs *actor_md5 = NULL; | ||
| 1511 | xs *lol = list_maint(user, NULL, 0); | ||
| 1512 | |||
| 1513 | if (uid) { | ||
| 1514 | if (!xs_is_hex(uid)) | ||
| 1515 | actor_md5 = xs_md5_hex(uid, strlen(uid)); | ||
| 1516 | else | ||
| 1517 | actor_md5 = xs_dup(uid); | ||
| 1518 | } | ||
| 1519 | |||
| 1520 | const xs_list *li; | ||
| 1521 | xs_list_foreach(lol, li) { | ||
| 1522 | const char *list_id = xs_list_get(li, 0); | ||
| 1523 | const char *list_title = xs_list_get(li, 1); | ||
| 1524 | if (uid) { | ||
| 1525 | xs *users = list_content(user, list_id, NULL, 0); | ||
| 1526 | if (xs_list_in(users, actor_md5) == -1) | ||
| 1527 | continue; | ||
| 1528 | } | ||
| 1529 | |||
| 1530 | xs *d = xs_dict_new(); | ||
| 1531 | |||
| 1532 | d = xs_dict_append(d, "id", list_id); | ||
| 1533 | d = xs_dict_append(d, "title", list_title); | ||
| 1534 | d = xs_dict_append(d, "replies_policy", "list"); | ||
| 1535 | d = xs_dict_append(d, "exclusive", xs_stock(XSTYPE_FALSE)); | ||
| 1536 | |||
| 1537 | out = xs_list_append(out, d); | ||
| 1538 | } | ||
| 1539 | |||
| 1540 | return out; | ||
| 1541 | } | ||
| 1542 | |||
| 1543 | |||
| 1503 | int mastoapi_get_handler(const xs_dict *req, const char *q_path, | 1544 | int mastoapi_get_handler(const xs_dict *req, const char *q_path, |
| 1504 | char **body, int *b_size, char **ctype, xs_str **link) | 1545 | char **body, int *b_size, char **ctype, xs_str **link) |
| 1505 | { | 1546 | { |
| @@ -1723,6 +1764,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1723 | if (strcmp(opt, "followers") == 0) { | 1764 | if (strcmp(opt, "followers") == 0) { |
| 1724 | out = xs_list_new(); | 1765 | out = xs_list_new(); |
| 1725 | } | 1766 | } |
| 1767 | else | ||
| 1768 | if (strcmp(opt, "lists") == 0) { | ||
| 1769 | out = mastoapi_account_lists(&snac1, uid); | ||
| 1770 | } | ||
| 1726 | 1771 | ||
| 1727 | user_free(&snac2); | 1772 | user_free(&snac2); |
| 1728 | } | 1773 | } |
| @@ -1744,6 +1789,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 */ | 1789 | /* implement empty response so apps like Tokodon don't show an error */ |
| 1745 | out = xs_list_new(); | 1790 | out = xs_list_new(); |
| 1746 | } | 1791 | } |
| 1792 | else | ||
| 1793 | if (strcmp(opt, "lists") == 0) { | ||
| 1794 | out = mastoapi_account_lists(&snac1, uid); | ||
| 1795 | } | ||
| 1747 | } | 1796 | } |
| 1748 | } | 1797 | } |
| 1749 | 1798 | ||
| @@ -1975,21 +2024,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1975 | else | 2024 | else |
| 1976 | if (strcmp(cmd, "/v1/lists") == 0) { /** list of lists **/ | 2025 | if (strcmp(cmd, "/v1/lists") == 0) { /** list of lists **/ |
| 1977 | if (logged_in) { | 2026 | if (logged_in) { |
| 1978 | xs *lol = list_maint(&snac1, NULL, 0); | 2027 | 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 | 2028 | ||
| 1994 | *body = xs_json_dumps(l, 4); | 2029 | *body = xs_json_dumps(l, 4); |
| 1995 | *ctype = "application/json"; | 2030 | *ctype = "application/json"; |