summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorGravatar grunfink2025-06-16 05:44:23 +0200
committerGravatar grunfink2025-06-16 05:44:23 +0200
commit5a0f23c76a989a389fa3cc1573bc73ef3031964f (patch)
treeddd65d13cf2e9742461b3385cc07d79c6c291545 /mastoapi.c
parentmastoapi: added entrypoint /v1/followed_tags. (diff)
downloadsnac2-5a0f23c76a989a389fa3cc1573bc73ef3031964f.tar.gz
snac2-5a0f23c76a989a389fa3cc1573bc73ef3031964f.tar.xz
snac2-5a0f23c76a989a389fa3cc1573bc73ef3031964f.zip
mastoapi: Added followed hashtag maintenance.
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 9437f27..2e8063b 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -3338,6 +3338,54 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
3338 } 3338 }
3339 } 3339 }
3340 else 3340 else
3341 if (xs_startswith(cmd, "/v1/tags/")) { /** **/
3342 if (logged_in) {
3343 xs *l = xs_split(cmd, "/");
3344 const char *i_tag = xs_list_get(l, 3);
3345 const char *cmd = xs_list_get(l, 4);
3346
3347 status = HTTP_STATUS_UNPROCESSABLE_CONTENT;
3348
3349 if (xs_is_string(i_tag) && xs_is_string(cmd)) {
3350 int ok = 0;
3351
3352 xs *tag = xs_fmt("#%s", i_tag);
3353 xs *followed_hashtags = xs_dup(xs_dict_get_def(snac.config,
3354 "followed_hashtags", xs_stock(XSTYPE_LIST)));
3355
3356 if (strcmp(cmd, "follow") == 0) {
3357 followed_hashtags = xs_list_append(followed_hashtags, tag);
3358 ok = 1;
3359 }
3360 else
3361 if (strcmp(cmd, "unfollow") == 0) {
3362 int off = xs_list_in(followed_hashtags, tag);
3363
3364 if (off != -1)
3365 followed_hashtags = xs_list_del(followed_hashtags, off);
3366
3367 ok = 1;
3368 }
3369
3370 if (ok) {
3371 /* update */
3372 xs_dict_set(snac.config, "followed_hashtags", followed_hashtags);
3373 user_persist(&snac, 0);
3374
3375 xs *d = xs_dict_new();
3376 xs *s = xs_fmt("%s?t=%s", srv_baseurl, i_tag);
3377 d = xs_dict_set(d, "name", i_tag);
3378 d = xs_dict_set(d, "url", s);
3379 d = xs_dict_set(d, "history", xs_stock(XSTYPE_LIST));
3380
3381 *body = xs_json_dumps(d, 4);
3382 *ctype = "application/json";
3383 status = HTTP_STATUS_OK;
3384 }
3385 }
3386 }
3387 }
3388 else
3341 status = HTTP_STATUS_UNPROCESSABLE_CONTENT; 3389 status = HTTP_STATUS_UNPROCESSABLE_CONTENT;
3342 3390
3343 /* user cleanup */ 3391 /* user cleanup */