diff options
| author | 2024-04-29 07:43:01 +0200 | |
|---|---|---|
| committer | 2024-04-29 07:43:01 +0200 | |
| commit | 8275a5f4d8764ebc9f9f82a4db377bacfa9fbc75 (patch) | |
| tree | 7d896846e16d6324d16e061a2bc08cfc0183efb0 /mastoapi.c | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-8275a5f4d8764ebc9f9f82a4db377bacfa9fbc75.tar.gz snac2-8275a5f4d8764ebc9f9f82a4db377bacfa9fbc75.tar.xz snac2-8275a5f4d8764ebc9f9f82a4db377bacfa9fbc75.zip | |
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, | |||
| 1767 | else | 1767 | else |
| 1768 | if (strcmp(cmd, "/v1/lists") == 0) { /** **/ | 1768 | if (strcmp(cmd, "/v1/lists") == 0) { /** **/ |
| 1769 | /* snac does not support lists */ | 1769 | /* snac does not support lists */ |
| 1770 | *body = xs_dup("[]"); | 1770 | if (logged_in) { |
| 1771 | *ctype = "application/json"; | 1771 | xs *lol = list_maint(&snac1, NULL, 0); |
| 1772 | status = 200; | 1772 | xs *l = xs_list_new(); |
| 1773 | int c = 0; | ||
| 1774 | xs_list *li; | ||
| 1775 | |||
| 1776 | while (xs_list_next(lol, &li, &c)) { | ||
| 1777 | xs *d = xs_dict_new(); | ||
| 1778 | |||
| 1779 | d = xs_dict_append(d, "id", xs_list_get(li, 0)); | ||
| 1780 | d = xs_dict_append(d, "title", xs_list_get(li, 1)); | ||
| 1781 | d = xs_dict_append(d, "replies_policy", "list"); | ||
| 1782 | d = xs_dict_append(d, "exclusive", xs_stock(XSTYPE_FALSE)); | ||
| 1783 | |||
| 1784 | l = xs_list_append(l, d); | ||
| 1785 | } | ||
| 1786 | |||
| 1787 | *body = xs_json_dumps(l, 4); | ||
| 1788 | *ctype = "application/json"; | ||
| 1789 | status = 200; | ||
| 1790 | } | ||
| 1773 | } | 1791 | } |
| 1774 | else | 1792 | else |
| 1775 | if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ | 1793 | if (strcmp(cmd, "/v1/scheduled_statuses") == 0) { /** **/ |
| @@ -2631,6 +2649,29 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 2631 | else | 2649 | else |
| 2632 | status = 401; | 2650 | status = 401; |
| 2633 | } | 2651 | } |
| 2652 | else | ||
| 2653 | if (strcmp(cmd, "/v1/lists") == 0) { | ||
| 2654 | if (logged_in) { | ||
| 2655 | const char *title = xs_dict_get(args, "title"); | ||
| 2656 | |||
| 2657 | if (xs_type(title) == XSTYPE_STRING) { | ||
| 2658 | /* add the list */ | ||
| 2659 | list_maint(&snac, title, 1); | ||
| 2660 | |||
| 2661 | xs *out = xs_dict_new(); | ||
| 2662 | |||
| 2663 | out = xs_dict_append(out, "title", title); | ||
| 2664 | out = xs_dict_append(out, "replies_policy", xs_dict_get_def(args, "replies_policy", "list")); | ||
| 2665 | out = xs_dict_append(out, "exclusive", xs_stock(XSTYPE_FALSE)); | ||
| 2666 | |||
| 2667 | *body = xs_json_dumps(out, 4); | ||
| 2668 | *ctype = "application/json"; | ||
| 2669 | status = 200; | ||
| 2670 | } | ||
| 2671 | else | ||
| 2672 | status = 422; | ||
| 2673 | } | ||
| 2674 | } | ||
| 2634 | 2675 | ||
| 2635 | /* user cleanup */ | 2676 | /* user cleanup */ |
| 2636 | if (logged_in) | 2677 | if (logged_in) |