commit 24f802b
default
·
2023-05-12 17:01:53 +0000 UTC
parent cada652
Use a different approach towards incomplete mentions. This time, incomplete mentions are completed using a) the host of the first mention, if there are any, or b) the current host.
2 files changed,
+47,
-46
+46,
-42
1@@ -368,6 +368,31 @@ void process_tags(snac *snac, const char *content, xs_str **n_content, xs_list *
2 xs_val *v;
3 int n = 0;
4
5+ /* create a default server for incomplete mentions */
6+ xs *def_srv = NULL;
7+
8+ if (xs_list_len(tl)) {
9+ /* if there are any mentions, get the server from
10+ the first one, which is the inReplyTo author */
11+ p = tl;
12+ while (xs_list_iter(&p, &v)) {
13+ const char *type = xs_dict_get(v, "type");
14+ const char *name = xs_dict_get(v, "name");
15+
16+ if (type && name && strcmp(type, "Mention") == 0) {
17+ xs *l = xs_split(name, "@");
18+
19+ def_srv = xs_dup(xs_list_get(l, -1));
20+
21+ break;
22+ }
23+ }
24+ }
25+
26+ if (xs_is_null(def_srv))
27+ /* use this same server */
28+ def_srv = xs_dup(xs_dict_get(srv_config, "host"));
29+
30 split = xs_regex_split(content, "(@[A-Za-z0-9_]+(@[A-Za-z0-9\\.-]+)?|&#[0-9]+;|#[^ ,\\.:;<]+)");
31
32 p = split;
33@@ -375,57 +400,36 @@ void process_tags(snac *snac, const char *content, xs_str **n_content, xs_list *
34 if ((n & 0x1)) {
35 if (*v == '@') {
36 xs *link = NULL;
37+ xs *wuid = NULL;
38
39 if (strchr(v + 1, '@') == NULL) {
40 /* only one @? it's a dumb Mastodon-like mention
41- without server; check if there is anybody
42- whose name starts with this in the tag list */
43- xs_list *p2 = tl;
44- xs_dict *v2;
45- xs *pname = xs_fmt("%s@", v);
46-
47- while (xs_list_iter(&p2, &v2)) {
48- const char *type = xs_dict_get(v2, "type");
49-
50- if (type && strcmp(type, "Mention") == 0) {
51- const char *name = xs_dict_get(v2, "name");
52- const char *href = xs_dict_get(v2, "href");
53-
54- if (name && href && (xs_startswith(name, pname) ||
55- xs_startswith(name, pname + 1))) {
56- /* good enough :shrug2: */
57- link = xs_fmt(
58- "<a href=\"%s\" class=\"u-url mention\">%s</a>", href, name);
59-
60- break;
61- }
62- }
63- }
64-
65- snac_debug(snac, 2, xs_fmt(
66- "mention without server '%s' (%s)", v, link ? link : "none"));
67+ without server; add the default one */
68+ wuid = xs_fmt("%s@%s", v, def_srv);
69+
70+ snac_debug(snac, 2, xs_fmt("mention without server '%s' '%s'", v, wuid));
71 }
72- else {
73- /* query the webfinger about this fellow */
74- xs *v2 = xs_strip_chars_i(xs_dup(v), "@.");
75- xs *actor = NULL;
76- xs *uid = NULL;
77- int status;
78+ else
79+ wuid = xs_dup(v);
80+
81+ /* query the webfinger about this fellow */
82+ xs *actor = NULL;
83+ xs *uid = NULL;
84+ int status;
85
86- status = webfinger_request(v2, &actor, &uid);
87+ status = webfinger_request(wuid, &actor, &uid);
88
89- if (valid_status(status)) {
90- xs *d = xs_dict_new();
91- xs *n = xs_fmt("@%s", uid);
92+ if (valid_status(status)) {
93+ xs *d = xs_dict_new();
94+ xs *n = xs_fmt("@%s", uid);
95
96- d = xs_dict_append(d, "type", "Mention");
97- d = xs_dict_append(d, "href", actor);
98- d = xs_dict_append(d, "name", n);
99+ d = xs_dict_append(d, "type", "Mention");
100+ d = xs_dict_append(d, "href", actor);
101+ d = xs_dict_append(d, "name", n);
102
103- tl = xs_list_append(tl, d);
104+ tl = xs_list_append(tl, d);
105
106- link = xs_fmt("<a href=\"%s\" class=\"u-url mention\">%s</a>", actor, n);
107- }
108+ link = xs_fmt("<a href=\"%s\" class=\"u-url mention\">%s</a>", actor, n);
109 }
110
111 if (!xs_is_null(link))
+1,
-4
1@@ -30,10 +30,7 @@ int webfinger_request(const char *qs, char **actor, char **user)
2 }
3 else {
4 /* it's a user */
5- xs *s = xs_dup(qs);
6-
7- if (xs_startswith(s, "@"))
8- s = xs_crop_i(s, 1, 0);
9+ xs *s = xs_strip_chars_i(xs_dup(qs), "@.");
10
11 l = xs_split_n(s, "@", 1);
12