From 085c5a545aa9b7112deabe9dc51e1f99906b7cab Mon Sep 17 00:00:00 2001
From: default
Date: Tue, 25 Jul 2023 12:31:42 +0200
Subject: Simplified attachment iteration in HTML rendering.
---
html.c | 91 +++++++++++++++++++++---------------------------------------------
1 file changed, 29 insertions(+), 62 deletions(-)
(limited to 'html.c')
diff --git a/html.c b/html.c
index 3e77b84..4f7f982 100644
--- a/html.c
+++ b/html.c
@@ -1173,7 +1173,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
}
/* make custom css for attachments easier */
- s = xs_str_cat(s, "
\n");
xs_list *p = attach;
@@ -1186,84 +1186,51 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
if (xs_is_null(t))
continue;
- if (xs_startswith(t, "image/") || strcmp(t, "Image") == 0) {
- char *url = xs_dict_get(v, "url");
- char *name = xs_dict_get(v, "name");
+ const char *url = xs_dict_get(v, "url");
+ if (xs_is_null(url))
+ url = xs_dict_get(v, "href");
+ if (xs_is_null(url))
+ continue;
- if (url != NULL) {
- if (xs_is_null(name))
- name = "";
+ const char *name = xs_dict_get(v, "name");
+ if (xs_is_null(name))
+ name = L("No description");
- xs *es1 = encode_html(name);
- xs *s1 = xs_fmt(
- "
"
- "
\n",
- url, url, es1, es1);
+ xs *es1 = encode_html(name);
+ xs *s1 = NULL;
- s = xs_str_cat(s, s1);
- }
+ if (xs_startswith(t, "image/") || strcmp(t, "Image") == 0) {
+ s1 = xs_fmt(
+ "
"
+ "
\n",
+ url, url, es1, es1);
}
else
if (xs_startswith(t, "video/")) {
- char *url = xs_dict_get(v, "url");
- char *name = xs_dict_get(v, "name");
-
- if (url != NULL) {
- if (xs_is_null(name))
- name = "No description";
-
- xs *es1 = encode_html(name);
- xs *s1 = xs_fmt("
\n", url, url, es1);
-
- s = xs_str_cat(s, s1);
- }
+ s1 = xs_fmt("
\n", url, url, es1);
}
else
if (xs_startswith(t, "audio/")) {
- char *url = xs_dict_get(v, "url");
- char *name = xs_dict_get(v, "name");
-
- if (url != NULL) {
- if (xs_is_null(name))
- name = "No description";
-
- xs *es1 = encode_html(name);
- xs *s1 = xs_fmt("
\n", url, url, es1);
-
- s = xs_str_cat(s, s1);
- }
+ s1 = xs_fmt("
\n", url, url, es1);
}
else
if (strcmp(t, "Link") == 0) {
- const char *url = xs_dict_get(v, "href");
-
- if (!xs_is_null(url)) {
- xs *es1 = encode_html(url);
- xs *s1 = xs_fmt("
%s
\n", url, es1);
- s = xs_str_cat(s, s1);
- }
+ xs *es2 = encode_html(url);
+ s1 = xs_fmt("
%s
\n", url, es2);
}
else {
- char *url = xs_dict_get(v, "url");
- char *name = xs_dict_get(v, "name");
-
- if (url != NULL) {
- if (xs_is_null(name))
- name = "No description";
-
- xs *es1 = encode_html(name);
- xs *s1 = xs_fmt("
Attachment: %s", url, es1);
-
- s = xs_str_cat(s, s1);
- }
+ s1 = xs_fmt("
Attachment: %s
\n", url, es1);
}
+
+ if (!xs_is_null(s1))
+ s = xs_str_cat(s, s1);
}
- s = xs_str_cat(s, "\n");
+ s = xs_str_cat(s, "
\n");
}
/* has this message an audience (i.e., comes from a channel or community)? */
--
cgit v1.2.3