commit 5a0f23c
grunfink
·
2025-06-16 03:44:23 +0000 UTC
parent f8055cc
mastoapi: Added followed hashtag maintenance.
1 files changed,
+48,
-0
+48,
-0
1@@ -3337,6 +3337,54 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
2 }
3 }
4 }
5+ else
6+ if (xs_startswith(cmd, "/v1/tags/")) { /** **/
7+ if (logged_in) {
8+ xs *l = xs_split(cmd, "/");
9+ const char *i_tag = xs_list_get(l, 3);
10+ const char *cmd = xs_list_get(l, 4);
11+
12+ status = HTTP_STATUS_UNPROCESSABLE_CONTENT;
13+
14+ if (xs_is_string(i_tag) && xs_is_string(cmd)) {
15+ int ok = 0;
16+
17+ xs *tag = xs_fmt("#%s", i_tag);
18+ xs *followed_hashtags = xs_dup(xs_dict_get_def(snac.config,
19+ "followed_hashtags", xs_stock(XSTYPE_LIST)));
20+
21+ if (strcmp(cmd, "follow") == 0) {
22+ followed_hashtags = xs_list_append(followed_hashtags, tag);
23+ ok = 1;
24+ }
25+ else
26+ if (strcmp(cmd, "unfollow") == 0) {
27+ int off = xs_list_in(followed_hashtags, tag);
28+
29+ if (off != -1)
30+ followed_hashtags = xs_list_del(followed_hashtags, off);
31+
32+ ok = 1;
33+ }
34+
35+ if (ok) {
36+ /* update */
37+ xs_dict_set(snac.config, "followed_hashtags", followed_hashtags);
38+ user_persist(&snac, 0);
39+
40+ xs *d = xs_dict_new();
41+ xs *s = xs_fmt("%s?t=%s", srv_baseurl, i_tag);
42+ d = xs_dict_set(d, "name", i_tag);
43+ d = xs_dict_set(d, "url", s);
44+ d = xs_dict_set(d, "history", xs_stock(XSTYPE_LIST));
45+
46+ *body = xs_json_dumps(d, 4);
47+ *ctype = "application/json";
48+ status = HTTP_STATUS_OK;
49+ }
50+ }
51+ }
52+ }
53 else
54 status = HTTP_STATUS_UNPROCESSABLE_CONTENT;
55