commit 2c8d4ce

default  ·  2024-05-09 07:09:22 +0000 UTC
parent 06599de
mastoapi: Added content search.
1 files changed,  +26, -4
+26, -4
 1@@ -2228,8 +2228,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2                 /* reply something only for offset 0; otherwise,
 3                    apps like Tusky keep asking again and again */
 4 
 5-                if (!xs_is_null(q) && !xs_is_null(type)) {
 6-                    if (strcmp(type, "accounts") == 0) {
 7+                if (!xs_is_null(q)) {
 8+                    if (xs_is_null(type) || strcmp(type, "accounts") == 0) {
 9                         /* do a webfinger query */
10                         char *actor = NULL;
11                         char *user  = NULL;
12@@ -2244,8 +2244,8 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
13                             }
14                         }
15                     }
16-                    else
17-                    if (strcmp(type, "hashtags") == 0) {
18+
19+                    if (xs_is_null(type) || strcmp(type, "hashtags") == 0) {
20                         /* search this tag */
21                         xs *tl = tag_search((char *)q, 0, 1);
22 
23@@ -2260,6 +2260,28 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
24                             htl = xs_list_append(htl, d);
25                         }
26                     }
27+
28+                    if (xs_is_null(type) || strcmp(type, "statuses") == 0) {
29+                        int to = 0;
30+                        xs *tl = content_search(&snac1, q, 1, 0, &to);
31+                        int c = 0;
32+                        char *v;
33+
34+                        while (xs_list_next(tl, &v, &c)) {
35+                            xs *post = NULL;
36+
37+                            if (!valid_status(timeline_get_by_md5(&snac1, v, &post)))
38+                                continue;
39+
40+                            char *type = xs_dict_get_def(post, "type", "-");
41+                            if (!xs_match(type, "Note|Article|Question|Page|Video"))
42+                                continue;
43+
44+                            xs *s = mastoapi_status(&snac1, post);
45+
46+                            stl = xs_list_append(stl, s);
47+                        }
48+                    }
49                 }
50             }
51