commit 916dc76

default  ·  2024-11-07 18:05:11 +0000 UTC
parent 3313dc8
Also use the proxy in replace_shortnames().
1 files changed,  +16, -9
M html.c
M html.c
+16, -9
 1@@ -60,7 +60,7 @@ xs_str *make_url(const char *href, const char *proxy)
 2 }
 3 
 4 
 5-xs_str *replace_shortnames(xs_str *s, const xs_list *tag, int ems)
 6+xs_str *replace_shortnames(xs_str *s, const xs_list *tag, int ems, const char *proxy)
 7 /* replaces all the :shortnames: with the emojis in tag */
 8 {
 9     if (!xs_is_null(tag)) {
10@@ -88,9 +88,11 @@ xs_str *replace_shortnames(xs_str *s, const xs_list *tag, int ems)
11 
12                 if (n && i) {
13                     const char *u = xs_dict_get(i, "url");
14+                    xs *url = make_url(u, proxy);
15+
16                     xs_html *img = xs_html_sctag("img",
17                         xs_html_attr("loading", "lazy"),
18-                        xs_html_attr("src", u),
19+                        xs_html_attr("src", url),
20                         xs_html_attr("style", style));
21 
22                     xs *s1 = xs_html_render(img);
23@@ -104,7 +106,7 @@ xs_str *replace_shortnames(xs_str *s, const xs_list *tag, int ems)
24 }
25 
26 
27-xs_str *actor_name(xs_dict *actor)
28+xs_str *actor_name(xs_dict *actor, const char *proxy)
29 /* gets the actor name */
30 {
31     const char *v;
32@@ -115,7 +117,7 @@ xs_str *actor_name(xs_dict *actor)
33         }
34     }
35 
36-    return replace_shortnames(xs_html_encode(v), xs_dict_get(actor, "tag"), 1);
37+    return replace_shortnames(xs_html_encode(v), xs_dict_get(actor, "tag"), 1, proxy);
38 }
39 
40 
41@@ -129,7 +131,7 @@ xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
42     int fwing = 0;
43     int fwer = 0;
44 
45-    xs *name = actor_name(actor);
46+    xs *name = actor_name(actor, proxy);
47 
48     /* get the avatar */
49     if ((v = xs_dict_get(actor, "icon")) != NULL) {
50@@ -700,6 +702,11 @@ xs_html *html_user_head(snac *user, const char *desc, const char *url)
51 
52 static xs_html *html_user_body(snac *user, int read_only)
53 {
54+    const char *proxy = NULL;
55+
56+    if (user && !read_only && xs_is_true(xs_dict_get(srv_config, "proxy_media")))
57+        proxy = user->actor;
58+
59     xs_html *body = xs_html_tag("body", NULL);
60 
61     /* top nav */
62@@ -845,7 +852,7 @@ static xs_html *html_user_body(snac *user, int read_only)
63         xs *bio1 = not_really_markdown(es1, NULL, &tags);
64         xs *bio2 = process_tags(user, bio1, &tags);
65 
66-        bio2 = replace_shortnames(bio2, tags, 2);
67+        bio2 = replace_shortnames(bio2, tags, 2, proxy);
68 
69         xs_html *top_user_bio = xs_html_tag("div",
70             xs_html_attr("class", "p-note snac-top-user-bio"),
71@@ -1648,7 +1655,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
72         }
73         else
74         if (valid_status(object_get_by_md5(p, &actor_r))) {
75-            xs *name = actor_name(actor_r);
76+            xs *name = actor_name(actor_r, proxy);
77 
78             if (!xs_is_null(name)) {
79                 xs *href = NULL;
80@@ -1786,7 +1793,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
81         c = xs_str_cat(c, "<p>");
82 
83         /* replace the :shortnames: */
84-        c = replace_shortnames(c, xs_dict_get(msg, "tag"), 2);
85+        c = replace_shortnames(c, xs_dict_get(msg, "tag"), 2, proxy);
86 
87         /* Peertube videos content is in markdown */
88         const char *mtype = xs_dict_get(msg, "mediaType");
89@@ -2652,7 +2659,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
90         if (!valid_status(actor_get(actor_id, &actor)))
91             continue;
92 
93-        xs *a_name = actor_name(actor);
94+        xs *a_name = actor_name(actor, proxy);
95         const char *label = type;
96 
97         if (strcmp(type, "Create") == 0)