From 5acf1395ec6d06d0ba1cae625471dee798ee9e77 Mon Sep 17 00:00:00 2001 From: default Date: Fri, 9 Feb 2024 21:24:44 +0100 Subject: [PATCH] mastoapi: added support for /api/v1/timelines/tag/. --- mastoapi.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mastoapi.c b/mastoapi.c index 267f842..6c0eee0 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1533,6 +1533,47 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, status = 200; } else + if (xs_startswith(cmd, "/v1/timelines/tag/")) { /** **/ + const char *limit_s = xs_dict_get(args, "limit"); + int limit = 0; + int cnt = 0; + + if (!xs_is_null(limit_s)) + limit = atoi(limit_s); + + if (limit == 0) + limit = 20; + + /* get the tag */ + xs *l = xs_split(cmd, "/"); + char *tag = xs_list_get(l, -1); + + xs *timeline = tag_search(tag, 0, limit); + xs *out = xs_list_new(); + xs_list *p = timeline; + xs_str *md5; + + while (xs_list_iter(&p, &md5) && cnt < limit) { + xs *msg = NULL; + + /* get the entry */ + if (!valid_status(object_get_by_md5(md5, &msg))) + continue; + + /* convert the Note into a Mastodon status */ + xs *st = mastoapi_status(NULL, msg); + + if (st != NULL) { + out = xs_list_append(out, st); + cnt++; + } + } + + *body = xs_json_dumps(out, 4); + *ctype = "application/json"; + status = 200; + } + else if (strcmp(cmd, "/v1/conversations") == 0) { /** **/ /* TBD */ *body = xs_dup("[]");