Browse Source

Added a skip argument to content_search().

default 11 months ago
parent
commit
1531e81a31
5 changed files with 19 additions and 11 deletions
  1. 9 4
      data.c
  2. 6 4
      html.c
  3. 1 1
      main.c
  4. 1 1
      mastoapi.c
  5. 2 1
      snac.h

+ 9 - 4
data.c

@@ -2491,7 +2491,8 @@ void notify_clear(snac *snac)
 
 /** 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 */
 {
     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(priv_tl, &priv_md5, &priv_c);
 
-    while (max_res > 0) {
+    while (show > 0) {
         char *md5 = NULL;
         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);
 
         if (xs_list_len(l)) {
-            xs_set_add(&seen, md5);
-            max_res--;
+            if (skip)
+                skip--;
+            else {
+                xs_set_add(&seen, md5);
+                show--;
+            }
         }
     }
 

+ 6 - 4
html.c

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

+ 1 - 1
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, XS_ALL, &to);
+        xs *r = content_search(&snac, url, 1, 0, XS_ALL, 10, &to);
 
         int c = 0;
         char *v;

+ 1 - 1
mastoapi.c

@@ -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) {
                         int to = 0;
                         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;
                         char *v;
 

+ 2 - 1
snac.h

@@ -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);
 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_get(const char *actor, xs_dict **data);