mastoapi: some search by content tweaks.

This commit is contained in:
default 2024-05-09 09:24:39 +02:00
parent 2c8d4ce6bd
commit 8de93b9cd7
2 changed files with 6 additions and 11 deletions

4
data.c
View file

@ -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");

View file

@ -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);
}
}
}