From 8de93b9cd72ef0cde8b5bb620f376e9b926354dd Mon Sep 17 00:00:00 2001 From: default Date: Thu, 9 May 2024 09:24:39 +0200 Subject: [PATCH] mastoapi: some search by content tweaks. --- data.c | 4 ++-- mastoapi.c | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/data.c b/data.c index d9449d8..75149e2 100644 --- a/data.c +++ b/data.c @@ -10,6 +10,7 @@ #include "xs_set.h" #include "xs_time.h" #include "xs_regex.h" +#include "xs_match.h" #include "snac.h" @@ -2570,8 +2571,7 @@ xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, i if (!valid_status(timeline_get_by_md5(user, md5, &post))) continue; - /* must be a Note */ - if (strcmp(xs_dict_get_def(post, "type", ""), "Note")) + if (!xs_match(xs_dict_get_def(post, "type", "-"), "Note|Question|Page|Article|Video")) continue; char *content = xs_dict_get(post, "content"); diff --git a/mastoapi.c b/mastoapi.c index e4bc116..253021b 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1467,9 +1467,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (limit == 0) limit = 20; - xs *ja = xs_json_dumps(args, 0); - snac_debug(&snac1, 1, xs_fmt("/v1/timelines/home: args='%s'", ja)); - xs *timeline = timeline_simple_list(&snac1, "private", 0, 2048); xs *out = xs_list_new(); @@ -2266,20 +2263,18 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, xs *tl = content_search(&snac1, q, 1, 0, &to); int c = 0; char *v; + int cnt = 40; - while (xs_list_next(tl, &v, &c)) { + while (xs_list_next(tl, &v, &c) && --cnt) { 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); + if (!xs_is_null(s)) + stl = xs_list_append(stl, s); } } }