commit 5acf139

default  ·  2024-02-09 20:24:44 +0000 UTC
parent 14a0cbd
mastoapi: added support for /api/v1/timelines/tag/.
1 files changed,  +41, -0
+41, -0
 1@@ -1533,6 +1533,47 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2         status = 200;
 3     }
 4     else
 5+    if (xs_startswith(cmd, "/v1/timelines/tag/")) { /** **/
 6+        const char *limit_s = xs_dict_get(args, "limit");
 7+        int limit = 0;
 8+        int cnt   = 0;
 9+
10+        if (!xs_is_null(limit_s))
11+            limit = atoi(limit_s);
12+
13+        if (limit == 0)
14+            limit = 20;
15+
16+        /* get the tag */
17+        xs *l = xs_split(cmd, "/");
18+        char *tag = xs_list_get(l, -1);
19+
20+        xs *timeline = tag_search(tag, 0, limit);
21+        xs *out      = xs_list_new();
22+        xs_list *p   = timeline;
23+        xs_str *md5;
24+
25+        while (xs_list_iter(&p, &md5) && cnt < limit) {
26+            xs *msg = NULL;
27+
28+            /* get the entry */
29+            if (!valid_status(object_get_by_md5(md5, &msg)))
30+                continue;
31+
32+            /* convert the Note into a Mastodon status */
33+            xs *st = mastoapi_status(NULL, msg);
34+
35+            if (st != NULL) {
36+                out = xs_list_append(out, st);
37+                cnt++;
38+            }
39+        }
40+
41+        *body  = xs_json_dumps(out, 4);
42+        *ctype = "application/json";
43+        status = 200;
44+    }
45+    else
46     if (strcmp(cmd, "/v1/conversations") == 0) { /** **/
47         /* TBD */
48         *body  = xs_dup("[]");