mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Added a maximum results argument to content_search().
This commit is contained in:
parent
8de93b9cd7
commit
cccc5454c2
4 changed files with 12 additions and 7 deletions
11
data.c
11
data.c
|
@ -2491,9 +2491,12 @@ void notify_clear(snac *snac)
|
|||
|
||||
/** searches **/
|
||||
|
||||
xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, int *timeout)
|
||||
xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, int max_res, int *timeout)
|
||||
/* returns a list of posts which content matches the regex */
|
||||
{
|
||||
if (regex == NULL || *regex == '\0')
|
||||
return xs_list_new();
|
||||
|
||||
xs_set seen;
|
||||
|
||||
xs_set_init(&seen);
|
||||
|
@ -2517,7 +2520,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(priv_tl, &priv_md5, &priv_c);
|
||||
|
||||
for (;;) {
|
||||
while (max_res > 0) {
|
||||
char *md5 = NULL;
|
||||
enum { NONE, PUBLIC, PRIVATE } from = NONE;
|
||||
|
||||
|
@ -2587,8 +2590,10 @@ xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, i
|
|||
/* apply regex */
|
||||
xs *l = xs_regex_select_n(c, regex, 1);
|
||||
|
||||
if (xs_list_len(l))
|
||||
if (xs_list_len(l)) {
|
||||
xs_set_add(&seen, md5);
|
||||
max_res--;
|
||||
}
|
||||
}
|
||||
|
||||
return xs_set_result(&seen);
|
||||
|
|
2
main.c
2
main.c
|
@ -379,7 +379,7 @@ int main(int argc, char *argv[])
|
|||
int to;
|
||||
|
||||
/* 'url' contains the regex */
|
||||
xs *r = content_search(&snac, url, 1, 10, &to);
|
||||
xs *r = content_search(&snac, url, 1, 10, XS_ALL, &to);
|
||||
|
||||
int c = 0;
|
||||
char *v;
|
||||
|
|
|
@ -2260,10 +2260,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||
|
||||
if (xs_is_null(type) || strcmp(type, "statuses") == 0) {
|
||||
int to = 0;
|
||||
xs *tl = content_search(&snac1, q, 1, 0, &to);
|
||||
int cnt = 40;
|
||||
xs *tl = content_search(&snac1, q, 1, 0, cnt, &to);
|
||||
int c = 0;
|
||||
char *v;
|
||||
int cnt = 40;
|
||||
|
||||
while (xs_list_next(tl, &v, &c) && --cnt) {
|
||||
xs *post = NULL;
|
||||
|
|
2
snac.h
2
snac.h
|
@ -179,7 +179,7 @@ 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);
|
||||
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 *timeout);
|
||||
xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, int max_res, int *timeout);
|
||||
|
||||
int actor_add(const char *actor, xs_dict *msg);
|
||||
int actor_get(const char *actor, xs_dict **data);
|
||||
|
|
Loading…
Reference in a new issue