diff options
| author | 2026-01-12 05:33:48 +0100 | |
|---|---|---|
| committer | 2026-01-12 05:33:48 +0100 | |
| commit | 54bb1626d2c6b55b4c331946606a9986ba963225 (patch) | |
| tree | f1222cf23f39e1f1a3a3688fc70d6b32f87e07b0 | |
| parent | Strip all HTML tags from pronouns. (diff) | |
| download | snac2-54bb1626d2c6b55b4c331946606a9986ba963225.tar.gz snac2-54bb1626d2c6b55b4c331946606a9986ba963225.tar.xz snac2-54bb1626d2c6b55b4c331946606a9986ba963225.zip | |
mastoapi: also return children of children.
| -rw-r--r-- | mastoapi.c | 51 |
1 files changed, 34 insertions, 17 deletions
| @@ -1809,6 +1809,37 @@ xs_list *mastoapi_account_lists(snac *user, const char *uid) | |||
| 1809 | } | 1809 | } |
| 1810 | 1810 | ||
| 1811 | 1811 | ||
| 1812 | xs_list *build_childrens(const xs_dict *msg, snac *snac1) { | ||
| 1813 | xs_list *ret = xs_list_new(); | ||
| 1814 | xs *children = object_children(xs_dict_get(msg, "id")); | ||
| 1815 | char *p = children; | ||
| 1816 | const xs_str *v; | ||
| 1817 | |||
| 1818 | while (xs_list_iter(&p, &v)) { | ||
| 1819 | xs *m2 = NULL; | ||
| 1820 | |||
| 1821 | if (valid_status(timeline_get_by_md5(snac1, v, &m2))) { | ||
| 1822 | if (xs_is_null(xs_dict_get(m2, "name"))) { | ||
| 1823 | xs *st = mastoapi_status(snac1, m2); | ||
| 1824 | |||
| 1825 | if (st) { | ||
| 1826 | /* childrens children */ | ||
| 1827 | xs *childs = build_childrens(m2, snac1); | ||
| 1828 | ret = xs_list_append(ret, st); | ||
| 1829 | if (xs_list_len(childs)) { | ||
| 1830 | char *p2 = childs; | ||
| 1831 | while (xs_list_iter(&p2, &v)) | ||
| 1832 | ret = xs_list_append(ret, v); | ||
| 1833 | |||
| 1834 | } | ||
| 1835 | } | ||
| 1836 | } | ||
| 1837 | } | ||
| 1838 | } | ||
| 1839 | return ret; | ||
| 1840 | } | ||
| 1841 | |||
| 1842 | |||
| 1812 | int mastoapi_get_handler(const xs_dict *req, const char *q_path, | 1843 | int mastoapi_get_handler(const xs_dict *req, const char *q_path, |
| 1813 | char **body, int *b_size, char **ctype, xs_str **link) | 1844 | char **body, int *b_size, char **ctype, xs_str **link) |
| 1814 | { | 1845 | { |
| @@ -2821,8 +2852,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 2821 | /* return ancestors and children */ | 2852 | /* return ancestors and children */ |
| 2822 | xs *anc = xs_list_new(); | 2853 | xs *anc = xs_list_new(); |
| 2823 | xs *des = xs_list_new(); | 2854 | xs *des = xs_list_new(); |
| 2824 | xs_list *p; | ||
| 2825 | const xs_str *v; | ||
| 2826 | char pid[MD5_HEX_SIZE]; | 2855 | char pid[MD5_HEX_SIZE]; |
| 2827 | 2856 | ||
| 2828 | /* build the [grand]parent list, moving up */ | 2857 | /* build the [grand]parent list, moving up */ |
| @@ -2842,21 +2871,9 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 2842 | } | 2871 | } |
| 2843 | 2872 | ||
| 2844 | /* build the children list */ | 2873 | /* build the children list */ |
| 2845 | xs *children = object_children(xs_dict_get(msg, "id")); | 2874 | xs *childs = build_childrens(msg, &snac1); |
| 2846 | p = children; | 2875 | if (xs_list_len(childs) > 0) |
| 2847 | 2876 | des = xs_list_cat(des, childs); | |
| 2848 | while (xs_list_iter(&p, &v)) { | ||
| 2849 | xs *m2 = NULL; | ||
| 2850 | |||
| 2851 | if (valid_status(timeline_get_by_md5(&snac1, v, &m2))) { | ||
| 2852 | if (xs_is_null(xs_dict_get(m2, "name"))) { | ||
| 2853 | xs *st = mastoapi_status(&snac1, m2); | ||
| 2854 | |||
| 2855 | if (st) | ||
| 2856 | des = xs_list_append(des, st); | ||
| 2857 | } | ||
| 2858 | } | ||
| 2859 | } | ||
| 2860 | 2877 | ||
| 2861 | out = xs_dict_new(); | 2878 | out = xs_dict_new(); |
| 2862 | out = xs_dict_append(out, "ancestors", anc); | 2879 | out = xs_dict_append(out, "ancestors", anc); |