diff options
| author | grunfink <grunfink@comam.es> | 2025-06-16 05:44:23 +0200 |
|---|---|---|
| committer | grunfink <grunfink@comam.es> | 2025-06-16 05:44:23 +0200 |
| commit | 5a0f23c76a989a389fa3cc1573bc73ef3031964f (patch) | |
| tree | ddd65d13cf2e9742461b3385cc07d79c6c291545 /mastoapi.c | |
| parent | f8055ccfb52c5fdf9c08b608060409625982cd05 (diff) | |
mastoapi: Added followed hashtag maintenance.
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 48 |
1 files changed, 48 insertions, 0 deletions
@@ -3338,6 +3338,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; /* user cleanup */ |