commit eacfa5b

default  ·  2024-01-11 05:08:52 +0000 UTC
parent e447d18
Avoid a webfinger request in msg_note().
1 files changed,  +16, -9
+16, -9
 1@@ -1204,18 +1204,25 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
 2                 to = xs_list_append(to, a);
 3 
 4             /* add this author to the tag list as a mention */
 5-            xs *t_href = NULL;
 6-            xs *t_name = NULL;
 7+            if (!xs_is_null(a)) {
 8+                xs *l = xs_split(a, "/");
 9+                xs *actor_o = NULL;
10 
11-            if (!xs_is_null(a) && valid_status(webfinger_request(a, &t_href, &t_name)
12-                && t_href && t_name)) {
13-                xs *t = xs_dict_new();
14+                if (xs_list_len(l) > 3 && valid_status(object_get(a, &actor_o))) {
15+                    char *uname = xs_dict_get(actor_o, "preferredUsername");
16 
17-                t = xs_dict_append(t, "type", "Mention");
18-                t = xs_dict_append(t, "href", t_href);
19-                t = xs_dict_append(t, "name", t_name);
20+                    if (!xs_is_null(uname) && *uname) {
21+                        xs *handle = xs_fmt("@%s@%s", uname, xs_list_get(l, 2));
22 
23-                tag = xs_list_append(tag, t);
24+                        xs *t = xs_dict_new();
25+
26+                        t = xs_dict_append(t, "type", "Mention");
27+                        t = xs_dict_append(t, "href", a);
28+                        t = xs_dict_append(t, "name", handle);
29+
30+                        tag = xs_list_append(tag, t);
31+                    }
32+                }
33             }
34 
35             /* get the context, if there is one */