commit 2111886
default
·
2023-11-27 20:28:27 +0000 UTC
parent 800bb01
Some html_entry() refactoring.
1 files changed,
+22,
-10
M
html.c
M
html.c
+22,
-10
1@@ -1298,23 +1298,32 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
2 else
3 s = xs_str_cat(s, "<div class=\"snac-child\">\n"); /** **/
4
5- s = xs_str_cat(s, "<div class=\"snac-post-header\">\n<div class=\"snac-score\">"); /** **/
6+ s = xs_str_cat(s, "<div class=\"snac-post-header\">\n"); /** **/
7+
8+ xs_html *score = xs_html_tag("div",
9+ xs_html_attr("class", "snac-score"));
10
11 if (user && is_pinned(user, id)) {
12 /* add a pin emoji */
13- xs *f = xs_fmt("<span title=\"%s\"> 📌 </span>", L("Pinned"));
14- s = xs_str_cat(s, f);
15+ xs_html_add(score,
16+ xs_html_tag("span",
17+ xs_html_attr("title", L("Pinned")),
18+ xs_html_raw(" 📌 ")));
19 }
20
21 if (strcmp(type, "Question") == 0) {
22 /* add the ballot box emoji */
23- xs *f = xs_fmt("<span title=\"%s\"> 🗳 </span>", L("Poll"));
24- s = xs_str_cat(s, f);
25+ xs_html_add(score,
26+ xs_html_tag("span",
27+ xs_html_attr("title", L("Poll")),
28+ xs_html_raw(" 🗳 ")));
29
30 if (user && was_question_voted(user, id)) {
31 /* add a check to show this poll was voted */
32- xs *f2 = xs_fmt("<span title=\"%s\"> ✓ </span>", L("Voted"));
33- s = xs_str_cat(s, f2);
34+ xs_html_add(score,
35+ xs_html_tag("span",
36+ xs_html_attr("title", L("Voted")),
37+ xs_html_raw(" ✓ ")));
38 }
39 }
40
41@@ -1324,13 +1333,16 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
42 int n_boosts = object_announces_len(id);
43
44 /* alternate emojis: %d 👍 %d 🔁 */
45-
46 xs *s1 = xs_fmt("%d ★ %d ↺\n", n_likes, n_boosts);
47
48- s = xs_str_cat(s, s1);
49+ xs_html_add(score,
50+ xs_html_raw(s1));
51 }
52
53- s = xs_str_cat(s, "</div>\n");
54+ {
55+ xs *s1 = xs_html_render(score);
56+ s = xs_str_cat(s, s1);
57+ }
58
59 if (boosts == NULL)
60 boosts = object_announces(id);