commit 127f409

default  ·  2024-03-02 04:56:02 +0000 UTC
parent 5431f6a
mastoapi: added search by tag.
1 files changed,  +27, -9
+27, -9
 1@@ -2031,18 +2031,36 @@ 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) && strcmp(type, "accounts") == 0) {
 6-                    /* do a webfinger query */
 7-                    char *actor = NULL;
 8-                    char *user  = NULL;
 9+                if (!xs_is_null(q) && !xs_is_null(type)) {
10+                    if (strcmp(type, "accounts") == 0) {
11+                        /* do a webfinger query */
12+                        char *actor = NULL;
13+                        char *user  = NULL;
14 
15-                    if (valid_status(webfinger_request(q, &actor, &user)) && actor) {
16-                        xs *actor_o = NULL;
17+                        if (valid_status(webfinger_request(q, &actor, &user)) && actor) {
18+                            xs *actor_o = NULL;
19 
20-                        if (valid_status(actor_request(&snac1, actor, &actor_o))) {
21-                            xs *acct = mastoapi_account(actor_o);
22+                            if (valid_status(actor_request(&snac1, actor, &actor_o))) {
23+                                xs *acct = mastoapi_account(actor_o);
24 
25-                            acl = xs_list_append(acl, acct);
26+                                acl = xs_list_append(acl, acct);
27+                            }
28+                        }
29+                    }
30+                    else
31+                    if (strcmp(type, "hashtags") == 0) {
32+                        /* search this tag */
33+                        xs *tl = tag_search((char *)q, 0, 1);
34+
35+                        if (xs_list_len(tl)) {
36+                            xs *d = xs_dict_new();
37+
38+                            d = xs_dict_append(d, "name", q);
39+                            xs *url = xs_fmt("%s?t=%s", srv_baseurl, q);
40+                            d = xs_dict_append(d, "url", url);
41+                            d = xs_dict_append(d, "history", xs_stock_list);
42+
43+                            htl = xs_list_append(htl, d);
44                         }
45                     }
46                 }