commit 8de93b9

default  ·  2024-05-09 07:24:39 +0000 UTC
parent 2c8d4ce
mastoapi: some search by content tweaks.
2 files changed,  +6, -11
M data.c
M data.c
+2, -2
 1@@ -10,6 +10,7 @@
 2 #include "xs_set.h"
 3 #include "xs_time.h"
 4 #include "xs_regex.h"
 5+#include "xs_match.h"
 6 
 7 #include "snac.h"
 8 
 9@@ -2570,8 +2571,7 @@ xs_list *content_search(snac *user, const char *regex, int priv, int max_secs, i
10         if (!valid_status(timeline_get_by_md5(user, md5, &post)))
11             continue;
12 
13-        /* must be a Note */
14-        if (strcmp(xs_dict_get_def(post, "type", ""), "Note"))
15+        if (!xs_match(xs_dict_get_def(post, "type", "-"), "Note|Question|Page|Article|Video"))
16             continue;
17 
18         char *content = xs_dict_get(post, "content");
+4, -9
 1@@ -1467,9 +1467,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2             if (limit == 0)
 3                 limit = 20;
 4 
 5-            xs *ja = xs_json_dumps(args, 0);
 6-            snac_debug(&snac1, 1, xs_fmt("/v1/timelines/home: args='%s'", ja));
 7-
 8             xs *timeline = timeline_simple_list(&snac1, "private", 0, 2048);
 9 
10             xs *out      = xs_list_new();
11@@ -2266,20 +2263,18 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
12                         xs *tl = content_search(&snac1, q, 1, 0, &to);
13                         int c = 0;
14                         char *v;
15+                        int cnt = 40;
16 
17-                        while (xs_list_next(tl, &v, &c)) {
18+                        while (xs_list_next(tl, &v, &c) && --cnt) {
19                             xs *post = NULL;
20 
21                             if (!valid_status(timeline_get_by_md5(&snac1, v, &post)))
22                                 continue;
23 
24-                            char *type = xs_dict_get_def(post, "type", "-");
25-                            if (!xs_match(type, "Note|Article|Question|Page|Video"))
26-                                continue;
27-
28                             xs *s = mastoapi_status(&snac1, post);
29 
30-                            stl = xs_list_append(stl, s);
31+                            if (!xs_is_null(s))
32+                                stl = xs_list_append(stl, s);
33                         }
34                     }
35                 }