From c110edce88cb3303b4d412b4e8802602fdf64a71 Mon Sep 17 00:00:00 2001 From: Uko Kokņevičs Date: Fri, 18 Apr 2025 23:32:05 +0000 Subject: Fix custom emojis not appearing This fixes emojis not appearing if source instance hasn't set the mediaType field. We use xs_mime_by_ext in order to guess whether the file is SVG or not when mediaType is missing. This commit also changes the behaviour to not replace :shortnames: with nothing when the emoji replacement failed. --- html.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index bcd71aa..5f0d75c 100644 --- a/html.c +++ b/html.c @@ -91,10 +91,14 @@ xs_str *replace_shortnames(xs_str *s, const xs_list *tag, int ems, const char *p const char *u = xs_dict_get(i, "url"); const char *mt = xs_dict_get(i, "mediaType"); - if (xs_is_string(u) && xs_is_string(mt)) { - if (strcmp(mt, "image/svg+xml") == 0 && !xs_is_true(xs_dict_get(srv_config, "enable_svg"))) - s = xs_replace_i(s, n, ""); - else { + if (xs_is_string(u)) { + if (!xs_is_string(mt)) + mt = xs_mime_by_ext(u); + + if (!xs_startswith(mt, "image/")) + continue; + + if (strcmp(mt, "image/svg+xml") != 0 || xs_is_true(xs_dict_get(srv_config, "enable_svg"))) { xs *url = make_url(u, proxy, 0); xs_html *img = xs_html_sctag("img", @@ -109,8 +113,6 @@ xs_str *replace_shortnames(xs_str *s, const xs_list *tag, int ems, const char *p s = xs_replace_i(s, n, s1); } } - else - s = xs_replace_i(s, n, ""); } } } -- cgit v1.2.3