commit 2b6d6d3

default  ·  2023-05-24 08:11:48 +0000 UTC
parent c356379
Finished polls are shown.
1 files changed,  +32, -1
M html.c
M html.c
+32, -1
 1@@ -729,7 +729,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
 2         return xs_str_cat(os, s);
 3     }
 4     else
 5-    if (strcmp(type, "Note") != 0) {
 6+    if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0) {
 7         /* skip oddities */
 8         return os;
 9     }
10@@ -881,6 +881,37 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
11             }
12         }
13 
14+        if (strcmp(type, "Question") == 0) {
15+            xs_list *oo = xs_dict_get(msg, "oneOf");
16+            xs_list *ao = xs_dict_get(msg, "anyOf");
17+            xs_list *p;
18+            xs_dict *v;
19+
20+            p = oo != NULL ? oo : ao;
21+
22+            if (!xs_is_null(xs_dict_get(msg, "closed"))) {
23+                /* closed poll */
24+                c = xs_str_cat(c, "<table>\n");
25+
26+                while (xs_list_iter(&p, &v)) {
27+                    const char *name       = xs_dict_get(v, "name");
28+                    const xs_dict *replies = xs_dict_get(v, "replies");
29+
30+                    if (name && replies) {
31+                        int nr = xs_number_get(xs_dict_get(replies, "totalItems"));
32+                        xs *l = xs_fmt("<tr><td>%s:</td><td>%d</td></tr>\n", name, nr);
33+
34+                        c = xs_str_cat(c, l);
35+                    }
36+                }
37+
38+                c = xs_str_cat(c, "</table>\n");
39+            }
40+            else {
41+                /* poll still active */
42+            }
43+        }
44+
45         s = xs_str_cat(s, c);
46     }
47