commit a0ae088
default
·
2023-11-28 18:07:29 +0000 UTC
parent d00ee22
More HTML gabagool.
1 files changed,
+128,
-122
M
html.c
M
html.c
+128,
-122
1@@ -1697,137 +1697,137 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
2
3 /* c contains sanitized HTML */
4 s = xs_str_cat(s, c);
5+ }
6
7- if (strcmp(type, "Question") == 0) { /** question content **/
8- xs_list *oo = xs_dict_get(msg, "oneOf");
9- xs_list *ao = xs_dict_get(msg, "anyOf");
10- xs_list *p;
11- xs_dict *v;
12- int closed = 0;
13+ if (strcmp(type, "Question") == 0) { /** question content **/
14+ xs_list *oo = xs_dict_get(msg, "oneOf");
15+ xs_list *ao = xs_dict_get(msg, "anyOf");
16+ xs_list *p;
17+ xs_dict *v;
18+ int closed = 0;
19
20- xs_html *poll = xs_html_tag("div", NULL);
21+ xs_html *poll = xs_html_tag("div", NULL);
22
23- if (xs_dict_get(msg, "closed"))
24- closed = 2;
25- else
26- if (user && xs_startswith(id, user->actor))
27- closed = 1; /* we questioned; closed for us */
28- else
29- if (user && was_question_voted(user, id))
30- closed = 1; /* we already voted; closed for us */
31-
32- /* get the appropriate list of options */
33- p = oo != NULL ? oo : ao;
34-
35- if (closed || user == NULL) {
36- /* closed poll */
37- xs_html *poll_result = xs_html_tag("table",
38- xs_html_attr("class", "snac-poll-result"));
39-
40- while (xs_list_iter(&p, &v)) {
41- char *name = xs_dict_get(v, "name");
42- xs_dict *replies = xs_dict_get(v, "replies");
43-
44- if (name && replies) {
45- char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems"));
46-
47- xs_html_add(poll_result,
48- xs_html_tag("tr",
49- xs_html_tag("td",
50- xs_html_text(name),
51- xs_html_text(":")),
52- xs_html_tag("td",
53- xs_html_text(ti))));
54- }
55- }
56+ if (xs_dict_get(msg, "closed"))
57+ closed = 2;
58+ else
59+ if (user && xs_startswith(id, user->actor))
60+ closed = 1; /* we questioned; closed for us */
61+ else
62+ if (user && was_question_voted(user, id))
63+ closed = 1; /* we already voted; closed for us */
64
65- xs_html_add(poll,
66- poll_result);
67- }
68- else {
69- /* poll still active */
70- xs *vote_action = xs_fmt("%s/admin/vote", user->actor);
71- xs_html *form;
72- xs_html *poll_form = xs_html_tag("div",
73- xs_html_attr("class", "snac-poll-form"),
74- form = xs_html_tag("form",
75- xs_html_attr("autocomplete", "off"),
76- xs_html_attr("method", "post"),
77- xs_html_attr("action", vote_action),
78- xs_html_sctag("input",
79- xs_html_attr("type", "hidden"),
80- xs_html_attr("name", "actor"),
81- xs_html_attr("value", actor)),
82- xs_html_sctag("input",
83- xs_html_attr("type", "hidden"),
84- xs_html_attr("name", "irt"),
85- xs_html_attr("value", id))));
86-
87- while (xs_list_iter(&p, &v)) {
88- char *name = xs_dict_get(v, "name");
89- xs_dict *replies = xs_dict_get(v, "replies");
90-
91- if (name) {
92- char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems"));
93-
94- xs_html_add(form,
95- xs_html_sctag("input",
96- xs_html_attr("type", !xs_is_null(oo) ? "radio" : "checkbox"),
97- xs_html_attr("id", name),
98- xs_html_attr("value", name),
99- xs_html_attr("name", "question")),
100- xs_html_text(" "),
101- xs_html_tag("span",
102- xs_html_attr("title", ti),
103- xs_html_text(name)),
104- xs_html_sctag("br", NULL));
105- }
106+ /* get the appropriate list of options */
107+ p = oo != NULL ? oo : ao;
108+
109+ if (closed || user == NULL) {
110+ /* closed poll */
111+ xs_html *poll_result = xs_html_tag("table",
112+ xs_html_attr("class", "snac-poll-result"));
113+
114+ while (xs_list_iter(&p, &v)) {
115+ char *name = xs_dict_get(v, "name");
116+ xs_dict *replies = xs_dict_get(v, "replies");
117+
118+ if (name && replies) {
119+ char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems"));
120+
121+ xs_html_add(poll_result,
122+ xs_html_tag("tr",
123+ xs_html_tag("td",
124+ xs_html_text(name),
125+ xs_html_text(":")),
126+ xs_html_tag("td",
127+ xs_html_text(ti))));
128 }
129+ }
130
131- xs_html_add(form,
132- xs_html_tag("p", NULL),
133+ xs_html_add(poll,
134+ poll_result);
135+ }
136+ else {
137+ /* poll still active */
138+ xs *vote_action = xs_fmt("%s/admin/vote", user->actor);
139+ xs_html *form;
140+ xs_html *poll_form = xs_html_tag("div",
141+ xs_html_attr("class", "snac-poll-form"),
142+ form = xs_html_tag("form",
143+ xs_html_attr("autocomplete", "off"),
144+ xs_html_attr("method", "post"),
145+ xs_html_attr("action", vote_action),
146 xs_html_sctag("input",
147- xs_html_attr("type", "submit"),
148- xs_html_attr("class", "button"),
149- xs_html_attr("value", L("Vote"))));
150+ xs_html_attr("type", "hidden"),
151+ xs_html_attr("name", "actor"),
152+ xs_html_attr("value", actor)),
153+ xs_html_sctag("input",
154+ xs_html_attr("type", "hidden"),
155+ xs_html_attr("name", "irt"),
156+ xs_html_attr("value", id))));
157
158- xs_html_add(poll,
159- poll_form);
160- }
161+ while (xs_list_iter(&p, &v)) {
162+ char *name = xs_dict_get(v, "name");
163+ xs_dict *replies = xs_dict_get(v, "replies");
164
165- /* if it's *really* closed, say it */
166- if (closed == 2) {
167- xs_html_add(poll,
168- xs_html_tag("p",
169- xs_html_text(L("Closed"))));
170- }
171- else {
172- /* show when the poll closes */
173- char *end_time = xs_dict_get(msg, "endTime");
174- if (!xs_is_null(end_time)) {
175- time_t t0 = time(NULL);
176- time_t t1 = xs_parse_iso_date(end_time, 0);
177-
178- if (t1 > 0 && t1 > t0) {
179- time_t diff_time = t1 - t0;
180- xs *tf = xs_str_time_diff(diff_time);
181- char *p = tf;
182-
183- /* skip leading zeros */
184- for (; *p == '0' || *p == ':'; p++);
185-
186- xs_html_add(poll,
187- xs_html_tag("p",
188- xs_html_text(L("Closes in")),
189- xs_html_text(" "),
190- xs_html_text(p)));
191- }
192+ if (name) {
193+ char *ti = (char *)xs_number_str(xs_dict_get(replies, "totalItems"));
194+
195+ xs_html_add(form,
196+ xs_html_sctag("input",
197+ xs_html_attr("type", !xs_is_null(oo) ? "radio" : "checkbox"),
198+ xs_html_attr("id", name),
199+ xs_html_attr("value", name),
200+ xs_html_attr("name", "question")),
201+ xs_html_text(" "),
202+ xs_html_tag("span",
203+ xs_html_attr("title", ti),
204+ xs_html_text(name)),
205+ xs_html_sctag("br", NULL));
206 }
207 }
208
209- xs *s1 = xs_html_render(poll);
210- s = xs_str_cat(s, s1);
211+ xs_html_add(form,
212+ xs_html_tag("p", NULL),
213+ xs_html_sctag("input",
214+ xs_html_attr("type", "submit"),
215+ xs_html_attr("class", "button"),
216+ xs_html_attr("value", L("Vote"))));
217+
218+ xs_html_add(poll,
219+ poll_form);
220 }
221+
222+ /* if it's *really* closed, say it */
223+ if (closed == 2) {
224+ xs_html_add(poll,
225+ xs_html_tag("p",
226+ xs_html_text(L("Closed"))));
227+ }
228+ else {
229+ /* show when the poll closes */
230+ char *end_time = xs_dict_get(msg, "endTime");
231+ if (!xs_is_null(end_time)) {
232+ time_t t0 = time(NULL);
233+ time_t t1 = xs_parse_iso_date(end_time, 0);
234+
235+ if (t1 > 0 && t1 > t0) {
236+ time_t diff_time = t1 - t0;
237+ xs *tf = xs_str_time_diff(diff_time);
238+ char *p = tf;
239+
240+ /* skip leading zeros */
241+ for (; *p == '0' || *p == ':'; p++);
242+
243+ xs_html_add(poll,
244+ xs_html_tag("p",
245+ xs_html_text(L("Closes in")),
246+ xs_html_text(" "),
247+ xs_html_text(p)));
248+ }
249+ }
250+ }
251+
252+ xs *s1 = xs_html_render(poll);
253+ s = xs_str_cat(s, s1);
254 }
255
256 s = xs_str_cat(s, "\n");
257@@ -1955,11 +1955,17 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
258 }
259
260 /* has this message an audience (i.e., comes from a channel or community)? */
261- const char *audience = xs_dict_get(msg, "audience");
262+ char *audience = xs_dict_get(msg, "audience");
263 if (strcmp(type, "Page") == 0 && !xs_is_null(audience)) {
264- xs *es1 = encode_html(audience);
265- xs *s1 = xs_fmt("<p>(<a href=\"%s\" title=\"%s\">%s</a>)</p>\n",
266- audience, L("Source channel or community"), es1);
267+ xs_html *au_tag = xs_html_tag("p",
268+ xs_html_text("("),
269+ xs_html_tag("a",
270+ xs_html_attr("href", audience),
271+ xs_html_attr("title", L("Source channel or community")),
272+ xs_html_text(audience)),
273+ xs_html_text(")"));
274+
275+ xs *s1 = xs_html_render(au_tag);
276 s = xs_str_cat(s, s1);
277 }
278