commit 21a99e5

green  ·  2025-04-09 01:09:53 +0000 UTC
parent 15100ad
emoji: refactor + emoji in display names on front page
3 files changed,  +29, -15
M html.c
M snac.h
M html.c
+25, -14
 1@@ -143,6 +143,26 @@ xs_str *actor_name(xs_dict *actor, const char *proxy)
 2 }
 3 
 4 
 5+xs_str *format_text_with_emoji(snac *user, const char *text, int ems, const char *proxy)
 6+/* needed when we have local text with no tags attached */
 7+{
 8+    xs *tags = xs_list_new();
 9+    xs *name1 = not_really_markdown(text, NULL, &tags);
10+
11+    xs_str *name3;
12+    if (user) {
13+        xs *name2 = process_tags(user, name1, &tags);
14+        name3 = sanitize(name2);
15+    }
16+    else {
17+        name3 = sanitize(name1);
18+        name3 = xs_replace_i(name3, "<br>", "");
19+    }
20+
21+    return replace_shortnames(name3, tags, ems, proxy);
22+}
23+
24+
25 xs_html *html_actor_icon(snac *user, xs_dict *actor, const char *date,
26                         const char *udate, const char *url, int priv,
27                         int in_people, const char *proxy, const char *lang,
28@@ -976,16 +996,12 @@ static xs_html *html_user_body(snac *user, int read_only)
29         xs_dict_get(user->config, "uid"),
30         xs_dict_get(srv_config, "host"));
31 
32-    // also try to make emojis render in local usernames, specifically in the user info thing in the web ui
33-    xs *name_tags = xs_list_new();
34-    xs *name1 = not_really_markdown(xs_dict_get(user->config, "name"), NULL, &name_tags);
35-    xs *name2 = sanitize(name1);
36-    name2 = replace_shortnames(name2, name_tags, 1, proxy);
37+    xs *display_name = format_text_with_emoji(NULL, xs_dict_get(user->config, "name"), 1, proxy);
38 
39     xs_html_add(top_user,
40         xs_html_tag("p",
41             xs_html_attr("class", "p-name snac-top-user-name"),
42-            xs_html_raw(name2)),
43+            xs_html_raw(display_name)),
44         xs_html_tag("p",
45             xs_html_attr("class", "snac-top-user-id"),
46             xs_html_text(handle)));
47@@ -1013,16 +1029,11 @@ static xs_html *html_user_body(snac *user, int read_only)
48     }
49 
50     if (read_only) {
51-        xs *tags = xs_list_new();
52-        xs *bio1 = not_really_markdown(xs_dict_get(user->config, "bio"), NULL, &tags);
53-        xs *bio2 = process_tags(user, bio1, &tags);
54-        xs *bio3 = sanitize(bio2);
55-
56-        bio3 = replace_shortnames(bio3, tags, 2, proxy);
57+        xs *bio = format_text_with_emoji(user, xs_dict_get(user->config, "bio"), 2, proxy);
58 
59         xs_html *top_user_bio = xs_html_tag("div",
60             xs_html_attr("class", "p-note snac-top-user-bio"),
61-            xs_html_raw(bio3)); /* already sanitized */
62+            xs_html_raw(bio)); /* already sanitized */
63 
64         xs_html_add(top_user,
65             top_user_bio);
66@@ -3675,7 +3686,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
67 
68             if (xs_is_true(xs_dict_get(srv_config, "strict_public_timelines")))
69                 list = timeline_simple_list(&snac, "public", skip, show, &more);
70-            else 
71+            else
72                 list = timeline_list(&snac, "public", skip, show, &more);
73 
74             xs *pins = pinned_list(&snac);
+3, -1
 1@@ -139,6 +139,8 @@ static xs_str *greeting_html(void)
 2                 snac user;
 3 
 4                 if (strcmp(uid, "relay") && user_open(&user, uid)) {
 5+                    xs *formatted_name = format_text_with_emoji(NULL, xs_dict_get(user.config, "name"), 1, NULL);
 6+
 7                     xs_html_add(ul,
 8                         xs_html_tag("li",
 9                             xs_html_tag("a",
10@@ -148,7 +150,7 @@ static xs_str *greeting_html(void)
11                                 xs_html_text("@"),
12                                 xs_html_text(host),
13                                 xs_html_text(" ("),
14-                                xs_html_text(xs_dict_get(user.config, "name")),
15+                                xs_html_raw(formatted_name),
16                                 xs_html_text(")"))));
17 
18                     user_free(&user);
M snac.h
+1, -0
1@@ -373,6 +373,7 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
2                              char **body, int *b_size, char **ctype);
3 
4 xs_dict *emojis(void);
5+xs_str *format_text_with_emoji(snac *user, const char *text, int ems, const char *proxy);
6 xs_str *not_really_markdown(const char *content, xs_list **attach, xs_list **tag);
7 xs_str *sanitize(const char *content);
8 xs_str *encode_html(const char *str);