Added a skip argument to content_search().

This commit is contained in:
default 2024-05-10 11:29:18 +02:00
parent 2b27a0d772
commit 1531e81a31
5 changed files with 19 additions and 11 deletions

11
data.c
View file

@ -2491,7 +2491,8 @@ void notify_clear(snac *snac)
/** searches **/ /** searches **/
xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, int max_res, int *timeout) xs_list *content_search(snac *user, const char *regex,
int priv, int skip, int show, int max_secs, int *timeout)
/* returns a list of posts which content matches the regex */ /* returns a list of posts which content matches the regex */
{ {
if (regex == NULL || *regex == '\0') if (regex == NULL || *regex == '\0')
@ -2520,7 +2521,7 @@ xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, i
xs_list_next(pub_tl, &pub_md5, &pub_c); xs_list_next(pub_tl, &pub_md5, &pub_c);
xs_list_next(priv_tl, &priv_md5, &priv_c); xs_list_next(priv_tl, &priv_md5, &priv_c);
while (max_res > 0) { while (show > 0) {
char *md5 = NULL; char *md5 = NULL;
enum { NONE, PUBLIC, PRIVATE } from = NONE; enum { NONE, PUBLIC, PRIVATE } from = NONE;
@ -2591,8 +2592,12 @@ xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, i
xs *l = xs_regex_select_n(c, regex, 1); xs *l = xs_regex_select_n(c, regex, 1);
if (xs_list_len(l)) { if (xs_list_len(l)) {
if (skip)
skip--;
else {
xs_set_add(&seen, md5); xs_set_add(&seen, md5);
max_res--; show--;
}
} }
} }

10
html.c
View file

@ -2563,20 +2563,22 @@ int html_get_handler(const xs_dict *req, const char *q_path,
char *q = xs_dict_get(q_vars, "q"); char *q = xs_dict_get(q_vars, "q");
if (q && *q) { if (q && *q) {
/* search by content */ /** search by content **/
int to = 0; int to = 0;
xs *tl = content_search(&snac, q, 1, skip ? 10 : 0, skip + show, &to); xs *tl = content_search(&snac, q, 1, skip, show, skip ? 10 : 0, &to);
xs *title = NULL; xs *title = NULL;
xs *page = xs_fmt("/admin?q=%s", q); xs *page = xs_fmt("/admin?q=%s", q);
int tl_len = xs_list_len(tl); int tl_len = xs_list_len(tl);
if (tl_len) if (tl_len)
title = xs_fmt(L("Search results for '%s'"), q); title = xs_fmt(L("Search results for '%s'"), q);
else
if (skip)
title = xs_fmt(L("No more matches for '%s'"), q);
else else
title = xs_fmt(L("Nothing found for '%s'"), q); title = xs_fmt(L("Nothing found for '%s'"), q);
*body = html_timeline(&snac, tl, 0, 0, tl_len, *body = html_timeline(&snac, tl, 0, skip, show, tl_len > 0, title, page, 1);
(to || tl_len == skip + show), title, page, 1);
*b_size = strlen(*body); *b_size = strlen(*body);
status = 200; status = 200;
} }

2
main.c
View file

@ -379,7 +379,7 @@ int main(int argc, char *argv[])
int to; int to;
/* 'url' contains the regex */ /* 'url' contains the regex */
xs *r = content_search(&snac, url, 1, 10, XS_ALL, &to); xs *r = content_search(&snac, url, 1, 0, XS_ALL, 10, &to);
int c = 0; int c = 0;
char *v; char *v;

View file

@ -2261,7 +2261,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
if (xs_is_null(type) || strcmp(type, "statuses") == 0) { if (xs_is_null(type) || strcmp(type, "statuses") == 0) {
int to = 0; int to = 0;
int cnt = 40; int cnt = 40;
xs *tl = content_search(&snac1, q, 1, 0, cnt, &to); xs *tl = content_search(&snac1, q, 1, 0, cnt, 0, &to);
int c = 0; int c = 0;
char *v; char *v;

3
snac.h
View file

@ -179,7 +179,8 @@ xs_list *list_timeline(snac *user, const char *list, int skip, int show);
xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op); xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op);
void list_distribute(snac *user, const char *who, const xs_dict *post); void list_distribute(snac *user, const char *who, const xs_dict *post);
xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, int max_res, int *timeout); xs_list *content_search(snac *user, const char *regex,
int priv, int skip, int show, int max_secs, int *timeout);
int actor_add(const char *actor, xs_dict *msg); int actor_add(const char *actor, xs_dict *msg);
int actor_get(const char *actor, xs_dict **data); int actor_get(const char *actor, xs_dict **data);