summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c89
1 files changed, 62 insertions, 27 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 6a12ced..dd80abc 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -1,5 +1,5 @@
1/* snac - A simple, minimalistic ActivityPub instance */ 1/* snac - A simple, minimalistic ActivityPub instance */
2/* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ 2/* copyright (c) 2022 - 2026 grunfink et al. / MIT license */
3 3
4#ifndef NO_MASTODON_API 4#ifndef NO_MASTODON_API
5 5
@@ -1171,6 +1171,10 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
1171 const char *content = xs_dict_get(msg, "content"); 1171 const char *content = xs_dict_get(msg, "content");
1172 const char *actor = xs_dict_get(msg, "actor"); 1172 const char *actor = xs_dict_get(msg, "actor");
1173 const xs_list *contentl = xs_dict_get(sfrl, content); 1173 const xs_list *contentl = xs_dict_get(sfrl, content);
1174
1175 if ((snac && is_muted(snac, actor)) || is_instance_blocked(actor))
1176 continue;
1177
1174 /* NOTE: idk when there are no actor, but i encountered that bug. 1178 /* NOTE: idk when there are no actor, but i encountered that bug.
1175 * Probably because of one of my previous attempts. 1179 * Probably because of one of my previous attempts.
1176 * Keeping this just in case, can remove later */ 1180 * Keeping this just in case, can remove later */
@@ -1805,6 +1809,37 @@ xs_list *mastoapi_account_lists(snac *user, const char *uid)
1805} 1809}
1806 1810
1807 1811
1812xs_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
1808int mastoapi_get_handler(const xs_dict *req, const char *q_path, 1843int mastoapi_get_handler(const xs_dict *req, const char *q_path,
1809 char **body, int *b_size, char **ctype, xs_str **link) 1844 char **body, int *b_size, char **ctype, xs_str **link)
1810{ 1845{
@@ -2612,19 +2647,33 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2612 if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/ 2647 if (strcmp(cmd, "/v1/custom_emojis") == 0) { /** **/
2613 xs *emo = emojis(); 2648 xs *emo = emojis();
2614 xs *list = xs_list_new(); 2649 xs *list = xs_list_new();
2615 int c = 0;
2616 const xs_str *k; 2650 const xs_str *k;
2617 const xs_val *v; 2651 const xs_val *v;
2618 while(xs_dict_next(emo, &k, &v, &c)) { 2652 xs_dict_foreach(emo, k, v) {
2619 xs *current = xs_dict_new(); 2653 xs *current = xs_dict_new();
2620 if (xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) { 2654 if ((xs_startswith(v, "https://") && xs_startswith((xs_mime_by_ext(v)), "image/")) || xs_type(v) == XSTYPE_DICT) {
2621 /* remove first and last colon */ 2655 /* remove first and last colon */
2622 xs *shortcode = xs_replace(k, ":", ""); 2656 if (xs_type(v) == XSTYPE_DICT) {
2623 current = xs_dict_append(current, "shortcode", shortcode); 2657 const char *v2;
2624 current = xs_dict_append(current, "url", v); 2658 const char *cat = k;
2625 current = xs_dict_append(current, "static_url", v); 2659 xs_dict_foreach(v, k, v2) {
2626 current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE)); 2660 xs *shortcode = xs_replace(k, ":", "");
2627 list = xs_list_append(list, current); 2661 current = xs_dict_append(current, "shortcode", shortcode);
2662 current = xs_dict_append(current, "url", v2);
2663 current = xs_dict_append(current, "static_url", v2);
2664 current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE));
2665 current = xs_dict_append(current, "category", cat);
2666 list = xs_list_append(list, current);
2667 }
2668 }
2669 else {
2670 xs *shortcode = xs_replace(k, ":", "");
2671 current = xs_dict_append(current, "shortcode", shortcode);
2672 current = xs_dict_append(current, "url", v);
2673 current = xs_dict_append(current, "static_url", v);
2674 current = xs_dict_append(current, "visible_in_picker", xs_stock(XSTYPE_TRUE));
2675 list = xs_list_append(list, current);
2676 }
2628 } 2677 }
2629 } 2678 }
2630 *body = xs_json_dumps(list, 0); 2679 *body = xs_json_dumps(list, 0);
@@ -2817,8 +2866,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2817 /* return ancestors and children */ 2866 /* return ancestors and children */
2818 xs *anc = xs_list_new(); 2867 xs *anc = xs_list_new();
2819 xs *des = xs_list_new(); 2868 xs *des = xs_list_new();
2820 xs_list *p;
2821 const xs_str *v;
2822 char pid[MD5_HEX_SIZE]; 2869 char pid[MD5_HEX_SIZE];
2823 2870
2824 /* build the [grand]parent list, moving up */ 2871 /* build the [grand]parent list, moving up */
@@ -2838,21 +2885,9 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2838 } 2885 }
2839 2886
2840 /* build the children list */ 2887 /* build the children list */
2841 xs *children = object_children(xs_dict_get(msg, "id")); 2888 xs *childs = build_childrens(msg, &snac1);
2842 p = children; 2889 if (xs_list_len(childs) > 0)
2843 2890 des = xs_list_cat(des, childs);
2844 while (xs_list_iter(&p, &v)) {
2845 xs *m2 = NULL;
2846
2847 if (valid_status(timeline_get_by_md5(&snac1, v, &m2))) {
2848 if (xs_is_null(xs_dict_get(m2, "name"))) {
2849 xs *st = mastoapi_status(&snac1, m2);
2850
2851 if (st)
2852 des = xs_list_append(des, st);
2853 }
2854 }
2855 }
2856 2891
2857 out = xs_dict_new(); 2892 out = xs_dict_new();
2858 out = xs_dict_append(out, "ancestors", anc); 2893 out = xs_dict_append(out, "ancestors", anc);