commit 7b8f766

default  ·  2024-12-19 04:00:23 +0000 UTC
parent 844825f
Searching for URLs brings a post to the user timeline.
1 files changed,  +45, -0
M html.c
M html.c
+45, -0
 1@@ -2996,6 +2996,51 @@ int html_get_handler(const xs_dict *req, const char *q_path,
 2         }
 3         else {
 4             const char *q = xs_dict_get(q_vars, "q");
 5+            xs *url_acct = NULL;
 6+
 7+            /* searching for an URL? */
 8+            if (q && xs_match(q, "https://*|http://*")) {
 9+                /* may by an actor; try a webfinger */
10+                xs *actor_obj = NULL;
11+
12+                if (valid_status(webfinger_request(q, &actor_obj, &url_acct))) {
13+                    /* it's an actor; do the dirty trick of changing q to the account name */
14+                    q = url_acct;
15+                }
16+                else {
17+                    /* if it's not already here, try to bring it to the user's timeline */
18+                    xs *md5 = xs_md5_hex(q, strlen(q));
19+
20+                    if (!timeline_here(&snac, md5)) {
21+                        xs *object = NULL;
22+                        int status;
23+
24+                        status = activitypub_request(&snac, q, &object);
25+                        snac_debug(&snac, 1, xs_fmt("Request searched URL %s %d", q, status));
26+
27+                        if (valid_status(status)) {
28+                            /* got it; also request the actor */
29+                            const char *attr_to = get_atto(object);
30+
31+                            if (!xs_is_null(attr_to)) {
32+                                status = actor_request(&snac, attr_to, &actor_obj);
33+
34+                                snac_debug(&snac, 1, xs_fmt("Request author %s of %s %d", attr_to, q, status));
35+
36+                                if (valid_status(status)) {
37+                                    /* add the actor */
38+                                    actor_add(attr_to, actor_obj);
39+
40+                                    /* add the post to the timeline */
41+                                    timeline_add(&snac, q, object);
42+                                }
43+                            }
44+                        }
45+                    }
46+                }
47+
48+                /* fall through */
49+            }
50 
51             if (q && *q) {
52                 if (xs_regex_match(q, "^@?[a-zA-Z0-9_]+@[a-zA-Z0-9-]+\\.")) {