commit c307e99

grunfink  ·  2026-04-27 06:07:32 +0000 UTC
parent 56d7d76
In URL searches, try first the ActivityPub object, then the Webfinger.

This fixes an error when searching for GotoSocial statuses,
as they are incorrectly identified as accounts.
1 files changed,  +30, -32
M html.c
M html.c
+30, -32
 1@@ -4761,48 +4761,46 @@ int html_get_handler(const xs_dict *req, const char *q_path,
 2 
 3             /* searching for an URL? */
 4             if (q && xs_match(q, "https://*|http://*")) {
 5-                /* may by an actor; try a webfinger */
 6+                /* bring it to the user's timeline */
 7                 xs *actor_obj = NULL;
 8+                xs *object = NULL;
 9+                int status;
10 
11-                if (valid_status(webfinger_request(q, &actor_obj, &url_acct)) && xs_is_string(url_acct)) {
12-                    /* it's an actor; do the dirty trick of changing q to the account name */
13-                    q = url_acct;
14-                }
15-                else {
16-                    /* bring it to the user's timeline */
17-                    xs *object = NULL;
18-                    int status;
19-
20-                    status = activitypub_request(&snac, q, &object);
21-                    snac_debug(&snac, 1, xs_fmt("Request searched URL %s %d", q, status));
22+                status = activitypub_request(&snac, q, &object);
23+                snac_debug(&snac, 1, xs_fmt("Request searched URL %s %d", q, status));
24 
25-                    if (valid_status(status)) {
26-                        /* got it; also request the actor */
27-                        const char *attr_to = get_atto(object);
28+                if (valid_status(status) && xs_is_dict(object)) {
29+                    /* got it; also request the actor */
30+                    const char *attr_to = get_atto(object);
31 
32-                        if (!xs_is_null(attr_to)) {
33-                            status = actor_request(&snac, attr_to, &actor_obj);
34+                    if (!xs_is_null(attr_to)) {
35+                        status = actor_request(&snac, attr_to, &actor_obj);
36 
37-                            if (valid_status(status)) {
38-                                /* reset the query string to be the real id */
39-                                url_acct = xs_dup(xs_dict_get(object, "id"));
40-                                q = url_acct;
41+                        if (valid_status(status)) {
42+                            /* reset the query string to be the real id */
43+                            url_acct = xs_dup(xs_dict_get(object, "id"));
44+                            q = url_acct;
45 
46-                                /* add the post to the timeline */
47-                                if (!timeline_here(&snac, q))
48-                                    timeline_add(&snac, q, object);
49-                            }
50+                            /* add the post to the timeline */
51+                            if (!timeline_here(&snac, q))
52+                                timeline_add(&snac, q, object);
53                         }
54-                        else {
55-                            /* retry webfinger, this time with the 'official' id */
56-                            const char *id = xs_dict_get(object, "id");
57+                    }
58+                    else {
59+                        /* retry webfinger, this time with the 'official' id */
60+                        const char *id = xs_dict_get(object, "id");
61 
62-                            if (xs_is_string(id) && valid_status(webfinger_request(id, &actor_obj, &url_acct)) &&
63-                                xs_is_string(url_acct))
64-                                q = url_acct;
65-                        }
66+                        if (xs_is_string(id) && valid_status(webfinger_request(id, &actor_obj, &url_acct)) &&
67+                            xs_is_string(url_acct))
68+                            q = url_acct;
69                     }
70                 }
71+                else
72+                /* may by an actor; try a webfinger */
73+                if (valid_status(webfinger_request(q, &actor_obj, &url_acct)) && xs_is_string(url_acct)) {
74+                    /* it's an actor; do the dirty trick of changing q to the account name */
75+                    q = url_acct;
76+                }
77 
78                 /* fall through */
79             }