snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit 2c8d4ce6bd227377fbfa02d92abdbff8a65150c3
parent 06599de966374f77fbcf71e85ce4a70080b8cf83
Author: default <nobody@localhost>
Date:   Thu,  9 May 2024 09:09:22 +0200

mastoapi: Added content search.

Diffstat:
Mmastoapi.c | 30++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/mastoapi.c b/mastoapi.c @@ -2228,8 +2228,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, /* reply something only for offset 0; otherwise, apps like Tusky keep asking again and again */ - if (!xs_is_null(q) && !xs_is_null(type)) { - if (strcmp(type, "accounts") == 0) { + if (!xs_is_null(q)) { + if (xs_is_null(type) || strcmp(type, "accounts") == 0) { /* do a webfinger query */ char *actor = NULL; char *user = NULL; @@ -2244,8 +2244,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, } } } - else - if (strcmp(type, "hashtags") == 0) { + + if (xs_is_null(type) || strcmp(type, "hashtags") == 0) { /* search this tag */ xs *tl = tag_search((char *)q, 0, 1); @@ -2260,6 +2260,28 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, htl = xs_list_append(htl, d); } } + + if (xs_is_null(type) || strcmp(type, "statuses") == 0) { + int to = 0; + xs *tl = content_search(&snac1, q, 1, 0, &to); + int c = 0; + char *v; + + while (xs_list_next(tl, &v, &c)) { + xs *post = NULL; + + if (!valid_status(timeline_get_by_md5(&snac1, v, &post))) + continue; + + char *type = xs_dict_get_def(post, "type", "-"); + if (!xs_match(type, "Note|Article|Question|Page|Video")) + continue; + + xs *s = mastoapi_status(&snac1, post); + + stl = xs_list_append(stl, s); + } + } } }