From 5a0f23c76a989a389fa3cc1573bc73ef3031964f Mon Sep 17 00:00:00 2001 From: grunfink Date: Mon, 16 Jun 2025 05:44:23 +0200 Subject: mastoapi: Added followed hashtag maintenance. --- mastoapi.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 9437f27..2e8063b 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -3337,6 +3337,54 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, } } } + else + if (xs_startswith(cmd, "/v1/tags/")) { /** **/ + if (logged_in) { + xs *l = xs_split(cmd, "/"); + const char *i_tag = xs_list_get(l, 3); + const char *cmd = xs_list_get(l, 4); + + status = HTTP_STATUS_UNPROCESSABLE_CONTENT; + + if (xs_is_string(i_tag) && xs_is_string(cmd)) { + int ok = 0; + + xs *tag = xs_fmt("#%s", i_tag); + xs *followed_hashtags = xs_dup(xs_dict_get_def(snac.config, + "followed_hashtags", xs_stock(XSTYPE_LIST))); + + if (strcmp(cmd, "follow") == 0) { + followed_hashtags = xs_list_append(followed_hashtags, tag); + ok = 1; + } + else + if (strcmp(cmd, "unfollow") == 0) { + int off = xs_list_in(followed_hashtags, tag); + + if (off != -1) + followed_hashtags = xs_list_del(followed_hashtags, off); + + ok = 1; + } + + if (ok) { + /* update */ + xs_dict_set(snac.config, "followed_hashtags", followed_hashtags); + user_persist(&snac, 0); + + xs *d = xs_dict_new(); + xs *s = xs_fmt("%s?t=%s", srv_baseurl, i_tag); + d = xs_dict_set(d, "name", i_tag); + d = xs_dict_set(d, "url", s); + d = xs_dict_set(d, "history", xs_stock(XSTYPE_LIST)); + + *body = xs_json_dumps(d, 4); + *ctype = "application/json"; + status = HTTP_STATUS_OK; + } + } + } + } else status = HTTP_STATUS_UNPROCESSABLE_CONTENT; -- cgit v1.2.3