commit 89b796f
default
·
2023-11-28 19:50:49 +0000 UTC
parent bd2540e
Blah blah blah html_entry() blah blah blah.
1 files changed,
+51,
-56
M
html.c
M
html.c
+51,
-56
1@@ -1436,7 +1436,6 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
2 char *id = xs_dict_get(msg, "id");
3 char *type = xs_dict_get(msg, "type");
4 char *actor;
5- int sensitive = 0;
6 char *v;
7 xs *boosts = NULL;
8
9@@ -1486,18 +1485,21 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
10 && !valid_status(actor_get(actor, NULL)))
11 return NULL;
12
13- xs_str *s = xs_str_new("<div>\n");
14+ /** html_entry top tag **/
15+ xs_html *entry_top = xs_html_tag("div", NULL);
16
17 {
18- xs *s1 = xs_fmt("<a name=\"%s_entry\"></a>\n", md5);
19-
20- s = xs_str_cat(s, s1);
21+ xs *s1 = xs_fmt("%s_entry", md5);
22+ xs_html_add(entry_top,
23+ xs_html_tag("a",
24+ xs_html_attr("name", s1)));
25 }
26
27- if (level == 0)
28- s = xs_str_cat(s, "<div class=\"snac-post\">\n"); /** **/
29- else
30- s = xs_str_cat(s, "<div class=\"snac-child\">\n"); /** **/
31+ xs_html *entry = xs_html_tag("div",
32+ xs_html_attr("class", level == 0 ? "snac-post" : "snac-child"));
33+
34+ xs_html_add(entry_top,
35+ entry);
36
37 /** post header **/
38
39@@ -1507,6 +1509,9 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
40 score = xs_html_tag("div",
41 xs_html_attr("class", "snac-score")));
42
43+ xs_html_add(entry,
44+ post_header);
45+
46 if (user && is_pinned(user, id)) {
47 /* add a pin emoji */
48 xs_html_add(score,
49@@ -1600,46 +1605,47 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
50 xs_html_add(post_header,
51 html_msg_icon(msg));
52
53- {
54- xs *s1 = xs_html_render(post_header);
55- s = xs_str_cat(s, s1);
56- }
57-
58 /** post content **/
59
60- s = xs_str_cat(s, "\n<div class=\"e-content snac-content\">\n"); /** **/
61+ xs_html *snac_content_wrap = xs_html_tag("div",
62+ xs_html_attr("class", "e-content snac-content"));
63+
64+ xs_html_add(entry,
65+ snac_content_wrap);
66
67 if (!xs_is_null(v = xs_dict_get(msg, "name"))) {
68- xs *es1 = encode_html(v);
69- xs *s1 = xs_fmt("<h3 class=\"snac-entry-title\">%s</h3>\n", es1);
70- s = xs_str_cat(s, s1);
71+ xs_html_add(snac_content_wrap,
72+ xs_html_tag("h3",
73+ xs_html_attr("class", "snac-entry-title"),
74+ xs_html_text(v)));
75 }
76
77+ xs_html *snac_content = NULL;
78+
79 /* is it sensitive? */
80 if (user && xs_type(xs_dict_get(msg, "sensitive")) == XSTYPE_TRUE) {
81 if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0')
82 v = "...";
83+
84 /* only show it when not in the public timeline and the config setting is "open" */
85 char *cw = xs_dict_get(user->config, "cw");
86 if (xs_is_null(cw) || local)
87 cw = "";
88- xs *es1 = encode_html(v);
89- xs *s1 = xs_fmt("<details %s><summary>%s [%s]</summary>\n", cw, es1, L("SENSITIVE CONTENT"));
90- s = xs_str_cat(s, s1);
91- sensitive = 1;
92- }
93
94-#if 0
95- {
96- xs *md5 = xs_md5_hex(id, strlen(id));
97- xs *s1 = xs_fmt("<p><code>%s</code></p>\n", md5);
98- s = xs_str_cat(s, s1);
99+ snac_content = xs_html_tag("details",
100+ xs_html_attr(cw, NULL),
101+ xs_html_tag("summary",
102+ xs_html_text(v),
103+ xs_html_text(L("[SENSITIVE CONTENT]"))));
104 }
105-#endif
106+ else
107+ snac_content = xs_html_tag("div", NULL);
108+
109+ xs_html_add(snac_content_wrap,
110+ snac_content);
111
112 {
113 /** build the content string **/
114-
115 char *content = xs_dict_get(msg, "content");
116
117 xs *c = sanitize(xs_is_null(content) ? "" : content);
118@@ -1695,7 +1701,8 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
119 }
120
121 /* c contains sanitized HTML */
122- s = xs_str_cat(s, c);
123+ xs_html_add(snac_content,
124+ xs_html_raw(c));
125 }
126
127 if (strcmp(type, "Question") == 0) { /** question content **/
128@@ -1825,12 +1832,10 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
129 }
130 }
131
132- xs *s1 = xs_html_render(poll);
133- s = xs_str_cat(s, s1);
134+ xs_html_add(snac_content_wrap,
135+ poll);
136 }
137
138- s = xs_str_cat(s, "\n");
139-
140 /* add the attachments */
141 v = xs_dict_get(msg, "attachment");
142
143@@ -1858,6 +1863,9 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
144 xs_html *content_attachments = xs_html_tag("div",
145 xs_html_attr("class", "snac-content-attachments"));
146
147+ xs_html_add(snac_content_wrap,
148+ content_attachments);
149+
150 xs_list *p = attach;
151
152 while (xs_list_iter(&p, &v)) {
153@@ -1946,11 +1954,6 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
154 xs_html_text(url))));
155 }
156 }
157-
158- {
159- xs *s1 = xs_html_render(content_attachments);
160- s = xs_str_cat(s, s1);
161- }
162 }
163
164 /* has this message an audience (i.e., comes from a channel or community)? */
165@@ -1964,21 +1967,15 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
166 xs_html_text(audience)),
167 xs_html_text(")"));
168
169- xs *s1 = xs_html_render(au_tag);
170- s = xs_str_cat(s, s1);
171+ xs_html_add(snac_content_wrap,
172+ au_tag);
173 }
174
175- if (sensitive)
176- s = xs_str_cat(s, "</details><p>\n");
177-
178- s = xs_str_cat(s, "</div>\n");
179-
180 /** controls **/
181
182 if (!local && user) {
183- xs_html *h = html_entry_controls(user, msg, md5);
184- xs *s1 = xs_html_render(h);
185- s = xs_str_cat(s, s1);
186+ xs_html_add(entry,
187+ html_entry_controls(user, msg, md5));
188 }
189
190 /** children **/
191@@ -1992,6 +1989,9 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
192 xs_html_tag("summary",
193 xs_html_text("...")));
194
195+ xs_html_add(entry,
196+ ch_details);
197+
198 xs_html *ch_container = xs_html_tag("div",
199 xs_html_attr("class", level < 4 ? "snac-children" : "snac-children-too-deep"));
200
201@@ -2033,15 +2033,10 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
202
203 left--;
204 }
205-
206- xs *s1 = xs_html_render(ch_details);
207- s = xs_str_cat(s, s1);
208 }
209 }
210
211- s = xs_str_cat(s, "</div>\n</div>\n");
212-
213- return s;
214+ return xs_html_render(entry_top);
215 }
216
217