commit 1531e81

default  ·  2024-05-10 09:29:18 +0000 UTC
parent 2b27a0d
Added a skip argument to content_search().
5 files changed,  +19, -11
M data.c
M html.c
M main.c
M snac.h
M data.c
+9, -4
 1@@ -2491,7 +2491,8 @@ void notify_clear(snac *snac)
 2 
 3 /** searches **/
 4 
 5-xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, int max_res, int *timeout)
 6+xs_list *content_search(snac *user, const char *regex,
 7+                int priv, int skip, int show, int max_secs, int *timeout)
 8 /* returns a list of posts which content matches the regex */
 9 {
10     if (regex == NULL || *regex == '\0')
11@@ -2520,7 +2521,7 @@ xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, i
12     xs_list_next(pub_tl,  &pub_md5,  &pub_c);
13     xs_list_next(priv_tl, &priv_md5, &priv_c);
14 
15-    while (max_res > 0) {
16+    while (show > 0) {
17         char *md5 = NULL;
18         enum { NONE, PUBLIC, PRIVATE } from = NONE;
19 
20@@ -2591,8 +2592,12 @@ xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, i
21         xs *l = xs_regex_select_n(c, regex, 1);
22 
23         if (xs_list_len(l)) {
24-            xs_set_add(&seen, md5);
25-            max_res--;
26+            if (skip)
27+                skip--;
28+            else {
29+                xs_set_add(&seen, md5);
30+                show--;
31+            }
32         }
33     }
34 
M html.c
+6, -4
 1@@ -2563,20 +2563,22 @@ int html_get_handler(const xs_dict *req, const char *q_path,
 2             char *q = xs_dict_get(q_vars, "q");
 3 
 4             if (q && *q) {
 5-                /* search by content */
 6+                /** search by content **/
 7                 int to = 0;
 8-                xs *tl = content_search(&snac, q, 1, skip ? 10 : 0, skip + show, &to);
 9+                xs *tl = content_search(&snac, q, 1, skip, show, skip ? 10 : 0, &to);
10                 xs *title = NULL;
11                 xs *page = xs_fmt("/admin?q=%s", q);
12                 int tl_len = xs_list_len(tl);
13 
14                 if (tl_len)
15                     title = xs_fmt(L("Search results for '%s'"), q);
16+                else
17+                if (skip)
18+                    title = xs_fmt(L("No more matches for '%s'"), q);
19                 else
20                     title = xs_fmt(L("Nothing found for '%s'"), q);
21 
22-                *body   = html_timeline(&snac, tl, 0, 0, tl_len,
23-                            (to || tl_len == skip + show), title, page, 1);
24+                *body   = html_timeline(&snac, tl, 0, skip, show, tl_len > 0, title, page, 1);
25                 *b_size = strlen(*body);
26                 status  = 200;
27             }
M main.c
+1, -1
1@@ -379,7 +379,7 @@ int main(int argc, char *argv[])
2         int to;
3 
4         /* 'url' contains the regex */
5-        xs *r = content_search(&snac, url, 1, 10, XS_ALL, &to);
6+        xs *r = content_search(&snac, url, 1, 0, XS_ALL, 10, &to);
7 
8         int c = 0;
9         char *v;
+1, -1
1@@ -2261,7 +2261,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2                     if (xs_is_null(type) || strcmp(type, "statuses") == 0) {
3                         int to = 0;
4                         int cnt = 40;
5-                        xs *tl = content_search(&snac1, q, 1, 0, cnt, &to);
6+                        xs *tl = content_search(&snac1, q, 1, 0, cnt, 0, &to);
7                         int c = 0;
8                         char *v;
9 
M snac.h
+2, -1
 1@@ -179,7 +179,8 @@ xs_list *list_timeline(snac *user, const char *list, int skip, int show);
 2 xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op);
 3 void list_distribute(snac *user, const char *who, const xs_dict *post);
 4 
 5-xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, int max_res, int *timeout);
 6+xs_list *content_search(snac *user, const char *regex,
 7+            int priv, int skip, int show, int max_secs, int *timeout);
 8 
 9 int actor_add(const char *actor, xs_dict *msg);
10 int actor_get(const char *actor, xs_dict **data);