diff options
| -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, | |||
| 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 */ |